Insufficient number of outputs from right hand side of equal sign to satisfy assignment.
1 次查看(过去 30 天)
显示 更早的评论
Hello
I am new to Matlab. I am trying to execute a script which has PID modelled. There is one main script which has overall code to be simulated and another script has PID controller. I am calling the main script which will call the PID controller function .Everytime i try to execute the main sscript it throws error as
"Insufficient number of outputs from right hand side of equal sign to satisfy assignment." .
Error in simulate (line 97)
[in,controller_params] = controller(controller_params,thetadot);
the variable controller_params is a structured array.
The function defined in PID controller script is :
function c = PID()
c = @(state, thetadot) pid_controller(state, thetadot);
end
function [inputs,state] = pid_controller(state, thetadot)
% Rest of the Code
end
I am unable to debug this error. Please help in understanding scenarios when it occurs and how do i resolve it.
Thanks
0 个评论
回答(1 个)
Adam Danz
2020-3-31
编辑:Adam Danz
2020-3-31
To address your question, an anonymous function only returns a single output. So,
x = PID(. . .) % This is fine, it returns 'inputs' from the pid_controller()
[x,y] = PID(. . .) % This produces an error since 'state' cannot be returned.
Why wrap the anonymous function within a function?
This function
function c = PID()
c = @(state, thetadot) pid_controller(state, thetadot);
end
merely returns a function handle that calls the pid_controller function. Why not just call that function directly and have access to both outputs?
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 PID Controller Tuning 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!