Simplify Matlab for/if statements further

조회 수: 1 (최근 30일)
deltanabla
deltanabla 2015년 2월 25일
편집: per isakson 2015년 2월 26일
Hi Folks,
This loop code is working fine but I would like to simplify it further. Can anyone help?
Basically, i need syntax to automate the row definitions of k, SE_ans and A, the columns are fine I think.
k is a 3*3 matrix, SE_ans is a 3*1 vector, A is a 3*3 identify matrix. The rests are just constants.
for i=1:size(k,1)
k(1,i)=subs(SE_ans(1,:),[theta_1, theta_2, theta_3, k_t1,k_t2,k_t3],[A(i,1), A(i,2), A(i,3),1,2,3])
k(1,i)=subs(SE_ans(1,:),[theta_1, theta_2, theta_3, k_t1,k_t2,k_t3],[A(i,1), A(i,2), A(i,3),1,2,3])
k(1,i)=subs(SE_ans(1,:),[theta_1, theta_2, theta_3, k_t1,k_t2,k_t3],[A(i,1), A(i,2), A(i,3),1,2,3])
k(2,i)=subs(SE_ans(2,:),[theta_1, theta_2, theta_3, k_t1,k_t2,k_t3],[A(i,1), A(i,2), A(i,3),1,2,3])
k(2,i)=subs(SE_ans(2,:),[theta_1, theta_2, theta_3, k_t1,k_t2,k_t3],[A(i,1), A(i,2), A(i,3),1,2,3])
k(2,i)=subs(SE_ans(2,:),[theta_1, theta_2, theta_3, k_t1,k_t2,k_t3],[A(i,1), A(i,2), A(i,3),1,2,3])
k(3,i)=subs(SE_ans(3,:),[theta_1, theta_2, theta_3, k_t1,k_t2,k_t3],[A(i,1), A(i,2), A(i,3),1,2,3])
k(3,i)=subs(SE_ans(3,:),[theta_1, theta_2, theta_3, k_t1,k_t2,k_t3],[A(i,1), A(i,2), A(i,3),1,2,3])
k(3,i)=subs(SE_ans(3,:),[theta_1, theta_2, theta_3, k_t1,k_t2,k_t3],[A(i,1), A(i,2), A(i,3),1,2,3])
end
thanks
  댓글 수: 1
per isakson
per isakson 2015년 2월 25일
편집: per isakson 2015년 2월 26일
Isn't it straight forward
tmp1 = [theta_1, theta_2, theta_3, k_t1,k_t2,k_t3];
for ii=1:size(k,1)
tmp2 = [A(ii,1:3),1,2,3];
for jj=1:size(k,2)
code
end
end
I guess I missed the point

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by