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!