Info

Questa domanda è chiusa. Riaprila per modificarla o per rispondere.

Numbering results from for loop with the iteration they come from

1 visualizzazione (ultimi 30 giorni)
I am trying to write code in order to output matrices K1,K2,K3,K4,K5, and K6. Below is the code I am trying to use but I am not able to number the K matrix within the loop. I am looking for a way to either make what I have work or otherwise differentiate the K matrix results as the loop runs.
EALtheta = [71.7 .0003 6.096 0 ; 71.7 .0003 7.620 45; 71.7 .0003 7.620 315; 71.7 .0003 4.572 90; 71.7 .0003 6.096 0; 71.7 .0003 4.572 90];
IDarray = [71.7 .0003 6.096 0 ; 71.7 .0003 7.620 45; 71.7 .0003 7.620 315; 71.7 .0003 4.572 90; 71.7 .0003 6.096 0; 71.7 .0003 4.572 90];
[m,n] = size(EALtheta);
for i = 1:m
C = cos( EALtheta(i,4) );
S = sin( EALtheta(i,4) );
k4x4 = [C^2 C*S -C^2 -C*S ; C*S S^2 -C*S -S^2 ; -C^2 -C*S C^2 C*S ; -C*S -S^2 C*S S^2];
K(i) = ( ( EALtheta(i,1) * EALtheta(i,2) ) / EALtheta(i,3) )* k4x4;
end

Risposte (2)

the cyclist
the cyclist il 5 Set 2020
Don't use separate variable names. Use the cell array data type:
K{i} = ( ( EALtheta(i,1) * EALtheta(i,2) ) / EALtheta(i,3) )* k4x4;

David Hill
David Hill il 5 Set 2020
Alturnatively, you could keep in a matrix where each row of K could be reshaped to the 4x4 matrix. No need for a for-loop.
EALtheta = [71.7 .0003 6.096 0 ; 71.7 .0003 7.620 45; 71.7 .0003 7.620 315; 71.7 .0003 4.572 90; 71.7 .0003 6.096 0; 71.7 .0003 4.572 90];
C = cos( EALtheta(:,4) );
S = sin( EALtheta(:,4) );
k = [C.^2,C.*S,-C.^2,C.*S,C.*S,S.^2,-C.*S,S.^2,-C.^2,-C.*S,C.^2,C.*S,-C.*S,-S.^2,C.*S,S.^2];
K = (EALtheta(:,1).*EALtheta(:,2)./EALtheta(:,3)).*k;

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by