matlab simulink error help me
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
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
M size is 1 X 181
W and S is constant
this code is matlab function's parameter in simulink
-----------------------------------------------------------------------------
function [D,cd]= fcn(S, W, M)
%#codegen
for i=1:181;
cl=W./(0.5*2116.2*1.4*S*M.^2);
if M(1,:)<=0.8 ;
cd0l=0.015;
k=1/(pi*6*0.7);
elseif M(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
Size mismatch (size [:? x 1] ~= size [181 x 1]).
Mismatched varying and fixed sizes indicate a probable run-time error. If this diagnostic is incorrect, use indexing to explicitly make the varying size fixed
Please tell me what the error is gone how
0 Commenti
Risposte (2)
Mitch Martelli
il 2 Dic 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);
for i=1:num_col;
cl(i)=W./(0.5*2116.2*1.4*S*M(i).^2);
if M(i)<=0.8 ;
cd0l(i)=0.015;
k(i)=1/(pi*6*0.7);
elseif M(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 Commenti
Mitch Martelli
il 3 Dic 2012
Without for loop :
cl_trial=W./(0.5*2116.2*1.4*S*M.^2);
cd0l_trial=(0.015+(3*0.015-0.015).*sin((M-0.8)./0.6*pi).^3);
k_trial=(1./(pi*6*(0.7-7*(M-0.8).^2+(M-0.8).^3).*22));
case_a=find(M<=0.8);
cd0l_trial(case_a)=0.015;
k_trial(case_a)=1/(pi*6*0.7);
case_b=find(M>=1.2);
cd0l_trial(case_b)=(0.015+(3*0.015-0.015)*(sin((2*pi)/3))^3);
k_trial(case_b)=(1/(pi*6*(0.7-7*(0.4)^2+22*(0.4)^3)));
cd_trial=cd0l+k.*cl_trial.^2;
D_trial=0.5.*cd.*1.4.*2116.2.*S.*M.^2;
Mitch Martelli
il 3 Dic 2012
M=rand(1,18100);
with for : Elapsed time is 4.856499 seconds.
without for : Elapsed time is 0.037057 seconds.
Sutae
il 2 Dic 2012
1 Commento
Walter Roberson
il 2 Dic 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.
Vedere anche
Categorie
Scopri di più su Computer Vision with Simulink in Help Center e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!