我是靠谱客的博主 笑点低果汁,这篇文章主要介绍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 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中划分两个不同内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(133)

评论列表共有 0 条评论

立即
投稿
返回
顶部