structure inside a function
이전 댓글 표시
Hey all!
I am having a ton of issues with this line of code. So I have this equation in a function in which I have made the structure "inputs" with the different aircraft properties. in a separate script, I have called the function and labeled again the inputs from my function page. Along with this, I have named my vmax.
I keep getting the same error message of too many input arguments. What am I getting wrong?
D = (0.5*rho0*((vmax*1.687810)^2)*inputs.S*inputs.Cd0)+(((inputs.WS*inputs.S)^2)/(0.5*rho0*((vmax*1.687810)^2)*inputs.E*inputs.AR*inputs.S*pi));
댓글 수: 9
Ameer Hamza
2020년 10월 12일
Can you show other parts of the code? Where are you creating the struct? How are you passing it to this function?
KSSV
2020년 10월 12일
Why did you hide the function names?
We cannot help you unless more details are given.
Also don't atatch your code as image snippet..copy and paste here.
KSSV
2020년 10월 12일
As you are suing inputs.S etc..ine formula...it is going to be an array....when you have array, you need to use element by element operations.
Ashlianne Sharma
2020년 10월 12일
Ashlianne Sharma
2020년 10월 12일
Stephen23
2020년 10월 12일
"Can you explain what you mean by element by element?"
Most likely you should be using array operations (i.e. element-by-element), not matrix operations:
Ashlianne Sharma
2020년 10월 12일
"I am really concerned about my equation having too many input values."
As Ameer Hamza explained, the cause of the error is your inadvertent use of comma-separated lists generated from a non-scalar structure:
Why do you define inputs as an input to the function hw_dragPower_sharmaAshlianne but then overwrite this with data inside the function? What is the point of that?
Ashlianne Sharma
2020년 10월 12일
채택된 답변
추가 답변 (1개)
If you have two equal vectors, like:
a = rand(1,3) ;
b = rand(1,3) ;
m = a.*b % this should be used. This iscalled element by element multiplication
d = a./b % element by element divison
p = a*b % this will trhow error.
l = a/b % this is not desired
In your case: Try the below. If any error, try using .*, ./ at vectors multiplication and divison.
D = (0.5*rho0*((vmax*1.687810)^2)*inputs.S.*inputs.Cd0)+(((inputs.WS.*inputs.S).^2)./(0.5*rho0*((vmax*1.687810)^2)*inputs.E.*inputs.AR.*inputs.S*pi));
댓글 수: 2
Ashlianne Sharma
2020년 10월 12일
KSSV
2020년 10월 12일
Try like this. If not working check the size of each S, Cd0, WS etc.....If still there is a error. Share your code. There should be some other problem.
S = [input.S] ;
Cd0 = [inputs.Cd0] ;
WS = [inputs.WS] ;
E = inputs.E] ;
AR = [inputs.AR] ;
D = (0.5*rho0*((vmax*1.687810)^2)*S.*Cd0)+(((WS.*S).^2)./(0.5*rho0*((vmax*1.687810)^2)*E.*AR.*S*pi));
카테고리
도움말 센터 및 File Exchange에서 Programming에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!