How to divide results into 3 columns?
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I have generated the following excel file using Matlab (see file attached). As you can see, I have 72 different records, separated by an empty line. How can I program my script so that I will have three columns: column 1 would be for records that have row=1, column 2 would be for records that have row=2, and column 3 would be for records that have row=3. I did it manually to demonstrate what I want (see image below):
This is the code I used:
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
%************Calculate Diff_irr here*************
ResultMtx = [ResultMtx;
m, o, r, t, Diff_irr];
end
ResultMtx = [ResultMtx;
nan nan nan nan nan];
end
end
end
ResultMtx = array2table(ResultMtx, 'VariableNames', ["Month","orientation", "rows", "tilt", "Irradiance"]);
writetable(ResultMtx, Result_File);
2 commentaires
Yazan
le 18 Août 2021
Do you mean that you need to group the table by Month and create nested tables? One table for Month =1, one for Month = 2, etc.
Réponses (1)
Image Analyst
le 18 Août 2021
Did you try
data = readmatrix('results.xlsx')
% Extract rows that have a 1 in column 1:
rowsWith1 = data(:, 1) == 1;
m1 = data(rowsWith1, :);
% Extract rows that have a 2 in column 1:
rowsWith2 = data(:, 1) == 2;
m2 = data(rowsWith2, :);
% Extract rows that have a 3 in column 1:
rowsWith3 = data(:, 1) == 3;
m3 = data(rowsWith3, :);
That will give double matrices.
If you want a table instead of a matrix you can do this:
data = readtable('results.xlsx')
% Extract rows that have a 1 in column 1:
rowsWith1 = data{:, 1} == 1;
t1 = data(rowsWith1, :);
% Extract rows that have a 2 in column 1:
rowsWith2 = data{:, 1} == 2;
t2 = data(rowsWith2, :);
% Extract rows that have a 3 in column 1:
rowsWith3 = data{:, 1} == 3;
t3 = data(rowsWith3, :);
2 commentaires
Image Analyst
le 18 Août 2021
writetable cannot write 3 tables as once. Check the documentation. You need to combine them before writing
t123 = [t1;t2;t3];
writetable(t123, Result_File);
Voir également
Catégories
En savoir plus sur Spreadsheets dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!