I'm trying to read a line from a text file. This line would be broken down into words by using textscan
. The output from textscan
would be stored inside an array of structures. Where each structure stores one word and the location it was at in the text file.
For example, the text file may look like this:
Result Time Margin Temperature
And I would like an array of structures where:
headerRow(1).header = Result
headerRow(1).location = 1
headerRow(2).header = Time
headerRow(2).location = 2
and so on. This is my code:
headerRow = struct( 'header', 'location' );
headerLine = fgets(currentFile)
temp_cellArray = textscan(headerLine, '%s', ' ')
for i = 1:size(temp_cellArray),
headerRow(i).header = temp_cellArray{i,1}
headerRow(i).location = i
end
But this only stores the whole 4x1 cell into the first element of the array. How can I make the code work as I would like it to?