I have a text file containing message and timestamps:
{193220,message,ucontroller9,controller1,lowalarm,success},
{193220,message,controller1,changer,{change,down},success},
{193220,controlaction,tapchange_down,{oldsetting,0.975},{newsetting,0.95}},
{193220,modelupdate_start,changeup,changer,193220},
{14430,modelupdate_complete},
{278480,message,ucontroller6,controller1,highalarm,success},
{278480,message,controller1,changer,{change,up},success},
...
I would like to read these lines into an array and re-order the array based on the first column. My approach so far has been as follows:
fid = fopen('messagestore.txt') % Open file
n=1
while 1
string = fgetl(fid); % get line
if ~ischar(string), break, end % break if end of file
string = strrep(string,'[',''); %
string = strrep(string,']',''); %
string = strrep(string,'{',''); % strip out unwanted characters
string = strrep(string,'}',''); %
string = strrep(string,',',' '); %
string = string(2:end); % remove space at start
MessageArray(:,n) = textscan(string,'%f%s%s%s%s%s'); % format and save into array
n=n+1;
end
fclose(fid)
This partially works but I am having a problem with discriminating between different message types (i.e. number of fields). I'm guessing that I could use the matlab sort function if I could just get the data into an array properly.
Is there a way to do this in matlab?