matlab循环遍历数组_如何在for循环matlab中划分两个不同的
数组
I am sorry for such a stupid question. I am not very good in programming and I am bad in MATLAB as well.
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.
My problem is how to locate and divide variable 1 to variable 16, variable 2 to variable 17, variable 3 to until it reach variable 15 divided to variable 30. I have MATLAB files attached to this question. Any help would be appreciated.
This is the main file
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
variable used in lambda
end
This is the function file related to m-file
function [value,position]= randomFunction(a)
y=randperm(length(a));
position=y(1);
value=a(position);
end
解决⽅案
To apply this division, use result(1:15)./result(16:30)
The operator ./ (or rdivide) divides each element in result(1:15) by the corresponding element in result(16:30)

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。