Why am I getting the 'Too many output arguments error'

Why am I getting the too many argument error for 'qi = Kp*error'?
clc;
clear;
close all;
%initializations go here
T = 0.1;
a = 1;
h = 1;
tfinal = 99;
Kp = 3;
for time = 0:T:tfinal
k = 0;
k = k+1;
qo(k) = 0.4;
qi=Kp*error; %proportional control law
if qi > 0.5, qi = 0.5;
end %saturation limit: upper value
if qi < 0, qi = 0;
end %saturation limit: lower value
h = h + (1/a)*T*( qi - qo(k)); %time evolution of the liquid level from the TF
error = r(k)-h; %error
tiempo(k) = time;
level(k) = h;
inflow(k) = qi;
end
figure(102)
plot(tiempo, inflow,'r')
ylabel({'$q_i(t)$'},'FontUnits','points','interpreter','latex','FontSize',13,'FontName','Times')
xlabel({'$time (s)$'},'FontUnits','points','interpreter','latex','FontSize',13,'FontName','Times')
title('Time evolution of the inflow rate')
figure(10)
plot(tiempo, level, 'r')
hold on
plot(tiempo, r, 'b')
hold on
ylabel({'$r(t)$'},'FontUnits','points','interpreter','latex','FontSize',13,'FontName','Times')
xlabel({'$time (s)$'},'FontUnits','points','interpreter','latex','FontSize',13,'FontName','Times')
title('Time evolution of the input and liquid level')

Answers (1)

dpb
dpb on 1 Dec 2016
Edited: dpb on 1 Dec 2016
error is a Matlab-supplied function which returns no outputs; hence trying to assign to a LHS fails. See
doc error % for details on that usage.
While you could alias the builtin; that is not recommended; instead, use some other name for an error magnitude variable... err might be a good choice--succinct but hardly likely to be misunderstood as to what is intended.

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Asked:

on 1 Dec 2016

Edited:

dpb
on 1 Dec 2016

Community Treasure Hunt

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

Start Hunting!