Question: Hi, Please check the matlab-code down below. It does what it should do, however I still have a problem with the legend. I would like

Hi,

Please check the matlab-code down below. It does what it should do, however I still have a problem with the legend. I would like to fix the legend : the legend has to display the plotted components: Qsh_demand and each of the existing components in the index_cell that have actually been plotted (of course correctly and with a different colour.

fid= fopen('C:\Users\...\Documents\sysfnd\00_Input\Input_Profiles\Variante01/demd_W_sh_converted_3600.inc'); %Call the hw_demand profile

a1= textscan(fid,'%f %f','headerlines',2);

fclose(fid);

fid= fopen('C:\Users\...\Documents\sysfnd\00_Input\Input_Profiles\Variante01/misc_Tamb_converted_3600.inc');

a2= textscan(fid,'%f %f','headerlines',2);

fclose(fid);

F= a2{1,2};

%plot(a2{1,2});

cd C:\Users\...\Documents\sysfnd\01_Output %paste the path to your 01_Output folder here

myFolder = pwd; % or 'C:\Users\yourUserName\Documents\My Pictures' or whatever...

if ~isfolder(myFolder)

errorMessage = sprintf('Error: The following folder does not exist: %s', myFolder);

uiwait(warndlg(errorMessage));

return;

end

filePattern = fullfile(myFolder, 'result*.mat'); % Change to whatever pattern you need.

theFiles = dir(filePattern);

for k = 1 : length(theFiles)

baseFileName = theFiles(k).name;

fullFileName = fullfile(myFolder, baseFileName);

fprintf(1, 'Now reading %s ', fullFileName);

thisStructure = load(fullFileName);

indexQsh = find(contains(thisStructure.output_profiles.P_Gen_Out.uels{1,3}, 'sh'));

indexNot_HP1 = find(contains(thisStructure.output_profiles.P_Gen_Out.uels{1,2},'FC_DE'));

indexNot_HP2 = find(contains(thisStructure.output_profiles.P_Gen_Out.uels{1,2},'E_heater_DE'));

indexNot_HP3 = find(contains(thisStructure.output_profiles.P_Gen_Out.uels{1,2},'Gas_condensing_system_DE'));

index_cell = {indexNot_HP1, indexNot_HP2, indexNot_HP3};

fig(k)= figure('name', sprintf('%s%s%d','sh_',baseFileName), 'NumberTitle', 'off');%figures are made here

for i = 1:length(index_cell)-1

current_index = index_cell{i};

next_index = index_cell{i+1};

hold on

scatter(a2{1,2}, a1{1,2}, 5, 'r');

if ~isempty(thisStructure.output_profiles.P_Gen_Out.val(:, current_index, indexQsh))

scatter(a2{1,2}, thisStructure.output_profiles.P_Gen_Out.val(:, current_index, indexQsh), 2, 'y');

elseif ~isempty(thisStructure.output_profiles.P_Gen_Out.val(:, next_index, indexQsh))

scatter(a2{1,2}, thisStructure.output_profiles.P_Gen_Out.val(:, next_index, indexQsh), 0.5, 'g');

elseif ~isempty(thisStructure.output_profiles.P_Gen_Out.val(:, current_index, indexQsh)) && ~isempty(thisStructure.output_profiles.P_Gen_Out.val(:, next_index, indexQsh))

scatter(a2{1,2},(thisStructure.output_profiles.P_Gen_Out.val(:, current_index, indexQsh)+thisStructure.output_profiles.P_Gen_Out.val(:, next_index, indexQsh)), 3, 'k');

hold off

else

disp('No values to plot')

end

xlabel('T_amb');

ylabel('Heizleistung kW');

title(baseFileName);

legend('Qsh demand', 'Generator 1', 'Generator 2','Generator 3', 'HP')

saveas(gcf,sprintf('%s%d', 'sh', k), "bmp");

end

end

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!