概述
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 variable 18....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
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)
最后
以上就是笑点低果汁为你收集整理的matlab循环遍历数组_如何在for循环matlab中划分两个不同的数组的全部内容,希望文章能够帮你解决matlab循环遍历数组_如何在for循环matlab中划分两个不同的数组所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复