1
votes

let us consider following data

SunDay  MonDay  TuesDay  WednesDay  ThursDay  FriDay  SatureDay
95.01   76.21   61.54    40.57       55.79    70.28   81.53
73.11   45.65   79.19    93.55       75.29    69.87   74.68
60.68   41.85   92.18    91.69       81.32    90.38   74.51
48.60   82.14   73.82    41.03       0.99     67.22   93.18
89.13   44.47   57.63    89.36       13.89    19.88   46.60

let us consider following code

filename = 'weeklydata.txt';
delimiterIn = ' ';
headerlinesIn = 1;
A = importdata(filename,delimiterIn,headerlinesIn);
% View data
for k = [1:7]
   disp(A.colheaders{1, k})
   disp(A.data(:, k))
   disp(' ')
end

i have several question related to this code ,what does

headerlinesIn = 1; and disp(A.colheaders{1, k}) do? for k=[1:7] is going from sunday to saturday,but this two lines i did not understand and please help me to clarify it

1

1 Answers

3
votes

The line headerlinesIn = 1 signalises the importdata function, that there is one line to skip at the beginning, which doesn't contain data. It is stored in A.colheaders, while your actual data is stored in A.data.

With disp(A.colheaders{1, k}) you now access and display this column headers, for k=1 the first one. With A.data(:, k) you now access and display the according data of the k-th column,.

So your loop basically prints the header of every column first, then the data of that column and finally an empty line. Then it jumps to the next column.


Regarding the comment: A.colheaders contains a cell array with 1 row and 7 columns of strings. A.colheaders{1, k} therefore gives you the string of the first row and k-th column. This string is simply displayed disp(...).