Output argument not assigned?

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 Commenti

I believe the output argument is clearly assigned in the second line of code
Torsten
Torsten il 26 Ott 2022
How do you call the function ?
[grill_state, SetTempC, SetTempF, Temp_F,Temp_C, Auger_RPM, Auger_PWM, Fan_PWM, Fan_RPM,P,I,D,u,glowplug_status]=ExtractDatafromtxt(file);
[PID_Performance,Grill_Status,Component_Performance]=getPerformancePlots(P,I,D,u,grill_state,Temp_F,Auger_RPM,Auger_PWM,Fan_PWM,glowplug_status);
here is the way it was called
The code looks fine. Then the logical conclusion is, that you do not run it, but another code. Maybe there is another instance of the getPerformancePlots.m file? There are 2 ways to check this:
which getPerformancePlots -all
or set a breakpoint in the code and check, if it is really reached.
Full output of the code is:
Component_Performance =
Figure (7) with properties:
Number: 7
Name: ''
Color: [0.9400 0.9400 0.9400]
Position: [488 342 560 420]
Units: 'pixels'
Show all properties
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);
which getPerformancePlots -all
R:\Nick Kavouris\MATLAB\getPerformancePlots.m
R:\Nick Kavouris\MATLAB\analysis functions\getPerformancePlots.m % Shadowed
Jan
Jan il 27 Ott 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?

Accedi per commentare.

Risposte (2)

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 Commenti

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
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.

Accedi per commentare.

sui en
sui en il 4 Apr 2023

0 voti

This problem is easy to solve, and when assigning a value to a variable in a function, it needs to be declared first.

Categorie

Richiesto:

il 26 Ott 2022

Risposto:

il 4 Apr 2023

Community Treasure Hunt

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

Start Hunting!

Translated by