matlab simulink error help me
1 view (last 30 days)
Show older comments
Hi I'm korean student
Error occurs I use the matlab in simlunk
I'm not actually sure why this error till you do not know how to fix
please teach me and help me matlab masters
code is
Msize is 1 X 181
Wand S is constant
this code is matlab function's parameter in simulink
-----------------------------------------------------------------------------
function[D,cd]= fcn(S, W, M)
%#codegen
fori=1:181;
cl=W./(0.5*2116.2*1.4*S*M.^2);
ifM(1,:)<=0.8 ;
cd0l=0.015;
k=1/(pi*6*0.7);
elseifM(1,:)>=1.2;
cd0l=(0.015+(3*0.015-0.015)*(sin((2*pi)/3))^3);
k=(1/(pi*6*(0.7-7*(0.4)^2+22*(0.4)^3)));
else
cd0l=(0.015+(3*0.015-0.015).*sin((M-0.8)./0.6*pi).^3);
k=(1./(pi*6*(0.7-7*(M-0.8).^2+(M-0.8).^3).*22));
end
cd=cd0l+k.*cl.^2*ones(1, 181);
D=0.5.*cd.*1.4.*2116.2.*S.*M.^2;
----------------------------------------------------------------------------
Where I want the value of the cd and D value. and Play the simulink and this error is
Sizemismatch (size [:? x 1] ~= size [181 x 1]).
Mismatchedvarying and fixed sizes indicate a probable run-time error.If this diagnostic is incorrect, useindexing to explicitly make the varying size fixed
Please tell me what the error is gone how
0 Comments
Answers (2)
Mitch Martelli
on 2 Dec 2012
Hi, You use a for statement but I cant see no one indexed variable inside the loop. Maybe you would like to to this :
num_col=size(M,2);
fori=1:num_col;
cl(i)=W./(0.5*2116.2*1.4*S*M(i).^2);
ifM(i)<=0.8 ;
cd0l(i)=0.015;
k(i)=1/(pi*6*0.7);
elseifM(i)>=1.2;
cd0l(i)=(0.015+(3*0.015-0.015)*(sin((2*pi)/3))^3);
k(i)=(1/(pi*6*(0.7-7*(0.4)^2+22*(0.4)^3)));
else
cd0l(i)=(0.015+(3*0.015-0.015).*sin((M(i)-0.8)./0.6*pi).^3);
k(i)=(1./(pi*6*(0.7-7*(M(i)-0.8).^2+(M(i)-0.8).^3).*22));
end
cd(i)=cd0l(i)+k(i).*cl(i).^2;
D(i)=0.5.*cd(i).*1.4.*2116.2.*S.*M(i).^2;
end
If yes, you can this program without use for statement in a easy form.
M1tCh
2 Comments
Mitch Martelli
on 3 Dec 2012
M=rand(1,18100);
with for : Elapsed time is 4.856499 seconds.
without for : Elapsed time is 0.037057 seconds.
Sutae
on 2 Dec 2012
1 Comment
Walter Roberson
on 2 Dec 2012
Pre-allocate "c1" and "cd01" and "k" and "cd" and "d"
Also double-check your complete routine for the case where M is empty.
See Also
下载188bet金宝搏
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!