Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

Numbering results from for loop with the iteration they come from

조회 수: 1 (최근 30일)
Grant Kuster
Grant Kuster 2020년 9월 5일
마감: MATLAB Answer Bot 2021년 8월 20일
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

답변 (2개)

the cyclist
the cyclist 2020년 9월 5일
Don't use separate variable names. Use the cell array data type:
K{i} = ( ( EALtheta(i,1) * EALtheta(i,2) ) / EALtheta(i,3) )* k4x4;
  댓글 수: 1
Grant Kuster
Grant Kuster 2020년 9월 5일
thats exactly what I was missing, thank you.

David Hill
David Hill 2020년 9월 5일
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