Simplify Matlab for/if statements further

1 Ansicht (letzte 30 Tage)
deltanabla
deltanabla am 25 Feb. 2015
Bearbeitet: per isakson am 26 Feb. 2015
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 Kommentar
per isakson
per isakson am 25 Feb. 2015
Bearbeitet: per isakson am 26 Feb. 2015
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

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by