I have a text file with 1151 lines and each line is comma separated with 20 numbers, like this:
@data
1,1,22,22,22,19,18,14,49.895756,17.775994,5.27092,0.771761,0.018632,0.006864,0.003923,0.003923,0.486903,0.100025,1,0
1,1,24,24,22,18,16,13,57.709936,23.799994,3.325423,0.234185,0.003903,0.003903,0.003903,0.003903,0.520908,0.144414,0,0
…
When I open a textfile with this code:
% Import data %
fid = fopen('assignment1.txt', 'r'); %Open text file
if fid == -1 %If failed to open
disp('Error, check file name') %Display error message
else %Imports all the text to a cell array
fmt = repmat('%f', 1, 20); S = textscan(fid, fmt, 'Delimiter', ',', 'CommentStyle', '@');end
I get a 1×20 cell array, where each entry is a 1151×1 double matrix.
I want it to be a 1×1151 cell array with 20×1 matrices instead. I want it that way because I need to randomly swap the positions of the rows between each other, not the columns.
Best Answer