I am trying to find the root mean square error(RMSE) but i am getting this error when I tried to find the output in command window 'Unrecognized function or variable 'Hot_Output'.

function [OBJ] = Main_Combined_optimization(Opt_Param)
%% code Description: Main optimization Function
%%Run Model with optimization Parameters
global hot;
Data = xlsread('hotspot.csv');
hot.RecordingTime = Data(:,1);
hot.Loading = Data(:,2);
hot.HotToTopOilGradient = Data(:,3);
t = hot.RecordingTime;
K = hot.Loading;
Hot_Output = hot.HotToTopOilGradient;
%% call the optimizer
[HotSpotTemperture_Optimization] = Combined_Optimization(K,Opt_Param,t);
error_HT = Hot_Output - HotSpotTemperture_Optimization;
OBJ_HT = sum( trapz(t, error_HT.^2));
OBJ = OBJ_HT;
%% Calculate the RMSE
RMSE = sqrt( sum((Hot_Output(:)- HotSpotTemperture_Optimization(:)).^2) / numel(Hot_Output) );
end

 Accepted Answer

That's a question of variable scope. Variables declared in a function are only visible within the function that declared it.
If you want to use that data after execution of the function, make it an output variable. If you just want to have a look at it for debugging, set a breakpoint in your function (go at this line: [HotSpotTemperture_Optimization] = Combined_Optimization(K,Opt_Param,t); where Hot_Temperature is already assigned.), then you will see all the variables in the workspace window.
Cheers
Manuel

5 Comments

I have tried it but it is not working. I am not sure how to make it an output variable as well.
What exactly have you tried?
See the doc's if you need instructions on how to debug:
When I set a breakpoint at that line, I can see all the variables created within the function, including Hot_Output.
To make it an output variable, change your function signature to
function [OBJ, Hot_Output] = Main_Combined_optimization(Opt_Param)
then you can call your function with
[obj, hot_output] = Main_Combined_optimization(Opt_Param);
then you get obj and hot_output in your workspace and you can also view them by typing them in the command window.
Cheers
Manuel

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!