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)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值