Insufficient number of outputs from right hand side of equal sign to satisfy assignment.

1 Ansicht (letzte 30 Tage)
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

Antworten (1)

Adam Danz
Adam Danz am 31 Mär. 2020
Bearbeitet: Adam Danz am 31 Mär. 2020
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?

Community Treasure Hunt

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

Start Hunting!

Translated by