How to write the output of program as a table on excel?

2 views (last 30 days)
Hannah
Hannah on 16 Aug 2021
Edited: TADA on 18 Aug 2021
How can I write the output of this code onto excel so that for a given a mon, o and r, I will have a table of tilt vs irr. specifically one entry would for example look like this:
mon=3 o=1 r=2
tilt irr
0 x1
10 x2
20 x3
30 x4
40 x5
50 x6
60 x7
70 x8
80 x9
90 x10
where the x values are given by the program.
My code is:
months=1:12;
orientation = [0, -90];
row = 1:3;
tilt = [0,10,20,30,40,50,60,70,80,90];
irr_cols=length(months)*length(orientation)*length(row);%72 columns
irr=zeros(length(tilt),irr_cols); %make an empty 10 by 72 matrix for irr
%%
%get values for the irr array
%where to get Meteonorm simulation hourly files
pathResults = sprintf('\\\\data-be\\data-ti-2019\\eit\\50_Labore\\T016-Photovoltaik_1\\06_Projekte\\02_Aktiv\\2019_Schenker_Storen\\DOCS_Hannah\\Experiment2\\03_Meteonorm_Output_Files\\01-EXP2_Monthly_Sim2\\');
for m=1:length(months) %loop 12 times for the 12 months
for o=1:length(orientation) %loop 2 times for south and east
for r = 1:length(row) %loop 3 times for the 3 rows
for t=1:length(tilt) %loop 10 times for the 10 tilting possibilities, this also represents the rows in the matric of irr
if o==1 %if south, get the file with an 'S' in the file name
tempFileName = sprintf('t%d_r%d_S-mon.txt',t,r);
elseif o==2 %if east, get the file with an 'E' in the file name
tempFileName = sprintf('t%d_r%d_E-mon.txt',t,r);
end
File_from_Meteo = append(pathResults, tempFileName); %Combine path and file name then assign it to the variable 'File_from_Meteo' to access the file
T = readtable(File_from_Meteo, 'Headerlines', 12); %table starts at line 12
%If the txt file is for t=1, (i.e. tilt of 0) it represents a situation with no tilt, therefore read colum "H_Ghhor"
if t<2
subset = T(m:m, 'H_Ghhor');
%Otherewise the txt file represents a situation with a tilt, therefore read colum "H_Gkhor"
else
subset = T(m:m,'H_Gkhor');
end
fprintf('mon=%d o=%d r=%d\n tilt=%d irr=%d\n\n',m,o,r,t,table2array(subset));
end
end
end
end
I've attached the current output as txt file.

Accepted Answer

TADA
TADA on 16 Aug 2021

A possible solution would be to add three more columns to the table, 'month', 'orientation' and 'row', after reading it from the file.

Then you should set these columns on all records of that given table to the loop indices.

Next, in each iteration of the loops you append the table to a larger table Then this table can be written to excel using writetable

  6 Comments

Sign in to comment.

More Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!