Borrar filtros
Borrar filtros

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

1 visualización (últimos 30 días)
Hannah
Hannah el 16 de Ag. de 2021
Editada: TADA el 18 de Ag. de 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.

Respuesta aceptada

TADA
TADA el 16 de Ag. de 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 comentarios
TADA
TADA el 17 de Ag. de 2021
Editada: TADA el 18 de Ag. de 2021
if two tables have the same columns, you can concat them vertically, just like you would a matrix:
x = 1:3;
y = 4:6;
t1 = table();
t1{1:3, {'x', 'y'}} = [x(:), y(:)];
t1 =
3×2 table
x y
_ _
1 4
2 5
3 6
t2 = table(x(:) * 10, y(:) * 10, 'VariableNames',{'x', 'y'})
t2 =
3×2 table
x y
__ __
10 40
20 50
30 60
T = [t1;t2]
T =
6×2 table
x y
__ __
1 4
2 5
3 6
10 40
20 50
30 60
Hannah
Hannah el 18 de Ag. de 2021
I got it now! Thank you so much :D

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Tables en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by