필터 지우기
필터 지우기

matlab simulink error help me

조회 수: 3 (최근 30일)
Sutae
Sutae 2012년 12월 1일
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

답변 (2개)

Mitch Martelli
Mitch Martelli 2012년 12월 2일
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
Mitch Martelli
Mitch Martelli 2012년 12월 3일
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
Mitch Martelli 2012년 12월 3일
M=rand(1,18100);
with for : Elapsed time is 4.856499 seconds.
without for : Elapsed time is 0.037057 seconds.

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


Sutae
Sutae 2012년 12월 2일
Thanks, but I was having gave an error occurs
This error is Undefined function or variable 'cl'. The first assignment to a local variable determines its class.
and cl &k cd0l else
In my opinion, (i) think using those things tell me if there is another way
Note that I will try to run this program(simulink in matlab use matlab function)
  댓글 수: 1
Walter Roberson
Walter Roberson 2012년 12월 2일
Pre-allocate "c1" and "cd01" and "k" and "cd" and "d"
Also double-check your complete routine for the case where M is empty.

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

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by