MATLAB Answers


for loop to do i calculations given i by user for each i columms n a matrix of k values array

Asked by Miguelcm90 on 13 Sep 2013

Hi everybody,

I have the following code;

cte_12 = abs((out(:,2).^-1).*(out(:,3)-out(:,2)).*((vt(2)-vt(1)).^-1).*(10^6));
cte_13 = abs((out(:,2).^-1).*(out(:,4)-out(:,2)).*((vt(3)-vt(1)).^-1).*(10^6));
cte_14 = abs((out(:,2).^-1).*(out(:,5)-out(:,2)).*((vt(4)-vt(1)).^-1).*(10^6));
cte_15 = abs((out(:,2).^-1).*(out(:,6)-out(:,2)).*((vt(5)-vt(1)).^-1).*(10^6));
cte_16 = abs((out(:,2).^-1).*(out(:,7)-out(:,2)).*((vt(6)-vt(1)).^-1).*(10^6));
cte_17 = abs((out(:,2).^-1).*(out(:,8)-out(:,2)).*((vt(7)-vt(1)).^-1).*(10^6));

where cte_1X are the array results I obtain with array calculations with the array [out] and the array [vt]

I want to do a loop to do this calculations, because every time I have to add or remove cte_1X, I have to add lines or remove them. Note that in calculations calculations the columm: out(:,2), it is allways the same, and vt(1) is a fixed array value of temperatures.

I allways start from cte_12 because it is a coefficient between two imput,such as out:(:,2) and out(:,3). and vt(2)-vt(1)

for example, I propose this: iterations = 6; ( because I have to do 6 calculations)

for i=2:iterations 
    cte1(i) = abs((out(:,2).^-1).*(out(:,(i+1))-out(:,2)).*((vt(i)-vt(1)).^-1).*(10^6));

I would have to save every cte1(i) for each columm in a new array. I am working with matrix, but I do not know how to loop inside this matrix and also inside of the new variable of iterations.

To finish, add that out(:,:) is a matrix of 2090x6 double and vt is an array

I can not make it work.

Any help is wellcome.

Thanks a lot.


Log in to comment.

0 Answers

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today