samedi 7 mars 2015

How to divide two different array in for loop 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

Aucun commentaire:

Enregistrer un commentaire