iteration on embedded matlab function
정보
이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.
이전 댓글 표시
hi all, i'm trying to do iteration in embedded matlab function. The coding as below:
function [P5,Q5,B5] = stats(Jacket5,E5,Mw5,Y5)
%#eml
%1st iteration
%---------------------------------------
t1 = NaN(10,1);
u1 = NaN(10,1);
w1 = NaN(3,1);
q1 = NaN(2,1);
p1 = NaN(3,1);
b2_1 = NaN(1,1);
nfactor = 1;
for l=1:nfactor
nn = 10;
t1=Jacket5;
t0=rand(nn,1);
u1=(Mw5);
k=1;
kmax=100;
while (k<kmax)
k=k+1;
t0 = t1;
w1=E5'*u1/(u1'*u1);
w1=w1/norm(w1);
t1=E5*w1;
q1=Y5'*t1/(t1'*t1);
q1=q1/norm(q1);
u1=Y5*q1/(q1'*q1);
end
p1=E5'*t1/(t1'*t1);
%regression
b2_1=u1'*t1/(t1'*t1);
end
%2nd iteration
%----------------------------------------
t2 = ones(10,1);
u2 = ones(10,1);
w2 = ones(3,1);
q2 = ones(2,1);
p2 = ones(3,1);
b2_2 = ones(1,1);
t2=t1;
u2=u1;
t0 = t2;
w2=E5'*u2/(u2'*u2);
w2=w2/norm(w2);
t2=E5*w2;
q2=Y5'*t2/(t2'*t2);
q2=q2/norm(q2);
u2=Y5*q2/(q2'*q2);
p2=E5'*t2/(t2'*t2);
%regression
b2_2=u2'*t2/(t2'*t2);
%3rd iteration
%--------------------------------------------------
t3 = NaN(10,1);
u3 = NaN(10,1);
w3 = NaN(3,1);
q3 = NaN(2,1);
p3 = NaN(3,1);
b2_3 = NaN(1,1);
nfactor = 1;
for l=1:nfactor
t3=t2;
u3=u2;
k=1;
kmax=100;
while (k<kmax)
k=k+1;
t0 = t3;
w3=E5'*u3/(u3'*u3);
w3=w3/norm(w3);
t3=E5*w3;
q3=Y5'*t3/(t3'*t3);
q3=q3/norm(q3);
u3=Y5*q3/(q3'*q3);
end
p3=E5'*t3/(t3'*t3);
%regression
b2_3=u3'*t3/(t3'*t3);
end
%store in matrices
T5 = [t1 t2 t3];
U5 = [u1 u2 u3];
W5 = [w1 w2 w3];
Q5 = [q1 q2 q3];
P5 = [p1 p2 p3];
B5 = [b2_1 b2_2 b2_3];
but the result of second and third iteration are same as the first iteration.Why?anyone have ideas why this happened?
댓글 수: 4
Image Analyst
2012년 7월 15일
Do you know how to use the debugger? That should help you figure it out. Otherwise you'd have to supply values for Jacket5,E5,Mw5,Y5 in case anyone wants to use the debugger themselves to figure it out for you (though it would be faster if you just learned how to set breakpoints and use the debugger yourself).
yana osman
2012년 7월 16일
yana osman
2012년 7월 16일
V Vaishnavi Kumar
2013년 1월 13일
Sir, i need to iterate an embedded matlab fcn in Simulink model for a particular no. of times. FOR and WHILE (command and iterator) are not appropriate, as the embedded block should get input and output at each iteration.
So i did this by using a digital clock input to the embedded block. thus a simple program is iterating (Simulation time / sample time of digital clock) no. of times properly...
the same logic with a lengthier program is not working, and its iterated unusually many no of times...
how this no of iterations can be controlled any idea
답변 (0개)
이 질문은 마감되었습니다.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!