Output argument not assigned?

4 次查看(过去 30 天)
Nicholas Kavouris
Nicholas Kavouris 2022-10-26
回答: sui en 2023-4-4
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 个评论
Nicholas Kavouris
Nicholas Kavouris 2022-10-26
which getPerformancePlots -all
R:\Nick Kavouris\MATLAB\getPerformancePlots.m
R:\Nick Kavouris\MATLAB\analysis functions\getPerformancePlots.m % Shadowed
Jan
Jan 2022-10-27
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 个)

Image Analyst
Image Analyst 2022-10-26
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 个评论
Nicholas Kavouris
Nicholas Kavouris 2022-10-27
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 2022-10-27
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
This problem is easy to solve, and when assigning a value to a variable in a function, it needs to be declared first.

类别

Help CenterFile Exchange 中查找有关 Line Plots 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by