what does a = T(m:m, 'label'); mean?

조회 수: 1 (최근 30일)
Hannah . 2021년 8월 17일
댓글: Hannah . 2021년 8월 17일
For each iteration, shown in the code below, I want to read the specified file starting from line 12; from line 12, I want to read one line per iteration. I will have 12 iterations in total represented by m., i.e. the first iteration, I want to read one line down from line 12, the second iteration I want to read the second line down from line 12 and so on until the last iteration where I read the 12th line down from line 12. 'H_Ghhor' and 'H_Gkhor' are the header labels for the columns I want to read.
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 t=1:length(tilt) %loop 10 times for the 10 tilting possibilities
for r = 1:length(row) %loop 3 times for the 3 rows
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);
File_from_Meteo = append(pathResults, tempFileName); %Combine path and file name
T = readtable(File_from_Meteo, 'Headerlines', 12); %table starts at line 12
if t==1
subset = T(m:m, 'H_Ghhor');
subset = T(m:m,'H_Gkhor');
Res_irr=table2array(subset); %the value of irr for a given m,o,r and t
My question is:
what does the line
subset = T(m:m, 'H_Ghhor');
exactly mean, and does it fulfil what I described above?

채택된 답변

Stephen23 2021년 8월 17일
편집: Stephen23 님. 2021년 8월 17일
"what does a = T(m:m, 'label'); mean?"
It refers to row m of variable/column "label" of the table T, returning a table:
The colon is not required. It seems that the author of that code also did not realize that they can access the data directly using curly braces (thus avoiding returning a table which then requires the superfluous TABLE2ARRAY):
subset = T{m,'H_Ghhor'};
% ^ ^ curly braces!
The robust, recommended, and OS-independent alternative to APPEND is to use FULLFILE.
"does it fulfil what I described above?"
It seems to do something like that. Usually it is more efficient to import data before the loop.
  댓글 수: 1
Hannah 2021년 8월 17일
Thank you for the explanation. I removed the colon and implemented the curly braces, so now my code is much better. :D

댓글을 달려면 로그인하십시오.

추가 답변 (0개)


Help CenterFile Exchange에서 Vector Volume Data에 대해 자세히 알아보기


Community Treasure Hunt

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

Start Hunting!

Translated by