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 个评论

I believe the output argument is clearly assigned in the second line of code
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
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?

请先登录,再进行评论。

回答(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 个评论

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.

请先登录,再进行评论。

sui en
sui en 2023-4-4

0 个投票

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

类别

帮助中心File Exchange 中查找有关 2-D and 3-D Plots 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by