필터 지우기
필터 지우기

Output argument not assigned?

조회 수: 5 (최근 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에서 Data Type Conversion에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by