Output argument not assigned?

15 views (last 30 days)
Nicholas Kavouris
Nicholas Kavouris on 26 Oct 2022
Answered: sui en on 4 Apr 2023
Recieve the Error Message When Executing this code, Why is this happening?
Output argument "PID_Performance" (and possibly others) not assigned a value in the execution with "getPerformancePlots" function.
Error in test (line 2)
[PID_Performance,Grill_Status,Component_Performance]=getPerformancePlots(P,I,D,u,grill_state,Temp_F,Auger_RPM,Auger_PWM,Fan_PWM,glowplug_status);
function[PID_Performance,Grill_Status,Component_Performance]=getPerformancePlots(P,I,D,u,grill_state, Temp_F, Auger_RPM, Auger_PWM, Fan_PWM,glowplug_status)
PID_Performance=figure('Name','PID Performance','WindowState','normal','Visible','on');
hold on;
yyaxis left
ylim([-2 2])
xlabel('Time (s)');
ylabel('PID Value');
yticks('auto');
plot(P,'Color', [.13 .13 .13],'LineStyle','-');
plot(I,'Color',[0.9290 0.6940 0.1250],'LineStyle','-');
plot(D,'Color',[0 0.4480 0.7410],'LineStyle','-');
plot(u,'r','LineStyle','-');
yyaxis right;
plot(Temp_F,'Color','#E0932C','LineWidth',1);
if numel(grill_state)>20000
xticks('auto');
elseif numel(grill_state)<5000
xticks(0:500:numel(grill_state));
else
xticks(0:1000:numel(grill_state));
end
ylabel('Temperature (F)');
grid on;
legend('P','I','D','u','Temp F','Location','southoutside','Orientation', 'horizontal');
hold off;
%% Create Grill Status Plot
Grill_Status=figure('Name','Grill Status','WindowState','normal','Visible','on');
grid on;
plot(glowplug_status,'Color','#D95319');
hold on;
plot(grill_state,'LineStyle','--','Color','#77AC30');
xlabel('Time (s)');
yticks(0:1:5)
if numel(grill_state)>20000
xticks(0:2000:numel(grill_state));
elseif numel(grill_state)>10000
xticks(0:1000:numel(grill_state));
else
xticks(0:500:numel(grill_state))
end
legend('Glowplug Status',"Grill State",'Location','southoutside','Orientation','horizontal')
%% Create Component Performance Plot
Component_Performance=figure('Name','Component Performance','WindowState','normal','Visible','on');
grid on;
xlabel('Time (s)');
if numel(grill_state)>20000
xticks("auto");
else
xticks(0:1000:numel(grill_state));
end
yyaxis right;
plot(Temp_F,'Color','#E0932C','LineWidth',1,"DisplayName","Probe Temp F");
hold on;
ylabel('Temperature (F)')
yyaxis left;
yticks(0:50:max(Auger_RPM.*100));
ylabel('PWM/RPM');
plot(Auger_PWM,'LineStyle','-','Color','#FAA533',"DisplayName","Auger PWM");
plot(Auger_RPM.*100,'LineStyle','-','Color','#21ABDE',"DisplayName","Auger RPM");
plot(Fan_PWM,'LineStyle','-','Color','#94918D',"DisplayName","Fan PWM");
legend('Location','southoutside','Orientation','horizontal')
end
>>
  7 Comments
Nicholas Kavouris
Nicholas Kavouris on 26 Oct 2022
which getPerformancePlots -all
R:\Nick Kavouris\MATLAB\getPerformancePlots.m
R:\Nick Kavouris\MATLAB\analysis functions\getPerformancePlots.m % Shadowed
Jan
Jan on 27 Oct 2022
You see, that there are 2 functions with the same name. Are you sure, that the posted function is the one, which produces the error message?

Sign in to comment.

Answers (2)

Image Analyst
Image Analyst on 26 Oct 2022
If you return output variables you need to set them. You did not for the Grill_Status and Component_Performance return variables. Try this:
function[PID_Performance, Grill_Status, Component_Performance]=getPerformancePlots(P,I,D,u,grill_state, Temp_F, Auger_RPM, Auger_PWM, Fan_PWM,glowplug_status)
% Initialize all return variables to null.
PID_Performance = [];
Grill_Status = [];
Component_Performance = [];
% Now start the function statements.
PID_Performance=figure('Name','PID Performance','WindowState','normal','Visible','on');
% and so on.
  2 Comments
Nicholas Kavouris
Nicholas Kavouris on 27 Oct 2022
Same Result, Output error message
function[PID_Performance,Grill_Status,Component_Performance]=getPerformancePlots(P,I,D,u,grill_state, Temp_F, Auger_RPM, Auger_PWM, Fan_PWM,glowplug_status)
PID_Performance = [];
Grill_Status = [];
Component_Performance = [];
PID_Performance=figure('Name','PID Performance','WindowState','normal','Visible','on');
hold on;
yyaxis left
ylim([-2 2])
xlabel('Time (s)');
ylabel('PID Value');
yticks('auto');
plot(P,'Color', [.13 .13 .13],'LineStyle','-');
plot(I,'Color',[0.9290 0.6940 0.1250],'LineStyle','-');
plot(D,'Color',[0 0.4480 0.7410],'LineStyle','-');
plot(u,'r','LineStyle','-');
yyaxis right;
plot(Temp_F,'Color','#E0932C','LineWidth',1);
if numel(grill_state)>20000
xticks('auto');
elseif numel(grill_state)<5000
xticks(0:500:numel(grill_state));
else
xticks(0:1000:numel(grill_state));
end
ylabel('Temperature (F)');
grid on;
legend('P','I','D','u','Temp F','Location','southoutside','Orientation', 'horizontal');
hold off;
%% Create Grill Status Plot
Grill_Status=figure('Name','Grill Status','WindowState','normal','Visible','on');
grid on;
plot(glowplug_status,'Color','#D95319');
hold on;
plot(grill_state,'LineStyle','--','Color','#77AC30');
xlabel('Time (s)');
yticks(0:1:5)
if numel(grill_state)>20000
xticks(0:2000:numel(grill_state));
elseif numel(grill_state)>10000
xticks(0:1000:numel(grill_state));
else
xticks(0:500:numel(grill_state))
end
legend('Glowplug Status',"Grill State",'Location','southoutside','Orientation','horizontal')
%% Create Component Performance Plot
Component_Performance=figure('Name','Component Performance','WindowState','normal','Visible','on');
grid on;
xlabel('Time (s)');
if numel(grill_state)>20000
xticks("auto");
else
xticks(0:1000:numel(grill_state));
end
yyaxis right;
plot(Temp_F,'Color','#E0932C','LineWidth',1,"DisplayName","Probe Temp F");
hold on;
ylabel('Temperature (F)')
yyaxis left;
yticks(0:50:max(Auger_RPM.*100));
ylabel('PWM/RPM');
plot(Auger_PWM,'LineStyle','-','Color','#FAA533',"DisplayName","Auger PWM");
plot(Auger_RPM.*100,'LineStyle','-','Color','#21ABDE',"DisplayName","Auger RPM");
plot(Fan_PWM,'LineStyle','-','Color','#94918D',"DisplayName","Fan PWM");
legend('Location','southoutside','Orientation','horizontal')
end
Image Analyst
Image Analyst on 27 Oct 2022
I don't see how it can say they're not assigned when you did it immediately upon entering. OK how about if the function definition is only these 4 lines:
function[PID_Performance, Grill_Status, Component_Performance]=getPerformancePlots(P,I,D,u,grill_state, Temp_F, Auger_RPM, Auger_PWM, Fan_PWM,glowplug_status)
% Initialize all return variables to null.
PID_Performance = [];
Grill_Status = [];
Component_Performance = [];
Try that. You'd better not get that "output arg not assigned" error or else you're not running the actual piece of code you think you are.

Sign in to comment.


sui en
sui en on 4 Apr 2023
This problem is easy to solve, and when assigning a value to a variable in a function, it needs to be declared first.

Categories

Find more on Data Type Conversion in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!