如何在for循环matlab中划分两个不同的数组 [英] How to divide two different array in for loop matlab
问题描述
我很抱歉这么愚蠢的问题。我编程不是很好,我在MATLAB中也很糟糕。
I am sorry for such a stupid question. I am not very good in programming and I am bad in MATLAB as well.
我的问题需要帮助。我正在生成一个代码,其中有 30个变量(用u表示)。我用它来循环。我的代码将产生值和每个变量的位置。
I need help to my problem. I am generating a code where it has 30 variables (denoted by u). I used for loop for this. My code will produce value and the position with each variables.
我的问题是如何找到变量1到变量16,变量2到变量17,变量3到变量18 ....然后到达变量15除以变量30 。我有MATLAB文件附加到这个问题。任何帮助将不胜感激。
My problem is how to locate and divide variable 1 to variable 16, variable 2 to variable 17, variable 3 to variable 18....until it reach variable 15 divided to variable 30. I have MATLAB files attached to this question. Any help would be appreciated.
这是主文件
start=zeros(2,15);
a=[-12 10 -5 3 21 19 3 7 17 21];
for u = 1:30;
acx = rand();
newacx = round(acx*100);
if (newacx < 10 || newacx == 10)
[valueone,positionone] = randomFunction(a);
elseif (newacx > 10)
[valueone,positionone] = max(start(1,:));
end
result(u) = valueone
% I want to divide result(1)/result(16),result(2)/result(17)...until result (15)/result(30)
resultX(u)= positionone
% I need to identify the position, which I can call when I need to analyze the data
end
这是与m文件相关的函数文件
function [value,position]= randomFunction(a)
y=randperm(length(a));
position=y(1);
value=a(position);
end
推荐答案
申请这个部门,使用结果(1:15)./ result(16:30)
运营商 ./
(或rdivide)将结果(1:15)
中的每个元素除以结果(16:30)
The operator ./
(or rdivide) divides each element in result(1:15)
by the corresponding element in result(16:30)
这篇关于如何在for循环matlab中划分两个不同的数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!