Prev: Matrix manipulation
Next: linear constraint question
From: Adam on 11 Jun 2010 13:58 Hi, I would like to log some variables each iteration of my program to a file of some kind. I would also like the user to be able to easily read this file via a view log type button. They should also be able to resume from where they left off, using what has been logged. I'm trying to decide if I should: a) Save the variables to a .mat file using save ... -append. Then generate an easy to read file when the use clicks. b)Save the variables to a .m file, then parse the data if loaded. I'm thinking I should go with saving the variables to .mat file, but am wondering if anyone knows of performance issues this way. Is saving a .mat file slower than writing a text file and vice-versa? I'm going to run some tests for now; but if anyone knows of the best ways to create logs that would be appreciated. Thanks
From: Adam on 11 Jun 2010 14:46 "Adam " <abc5(a)ubc.ca> wrote in message <huttfe$kb9$1(a)fred.mathworks.com>... > Hi, > > I would like to log some variables each iteration of my program to a file of some kind. I would also like the user to be able to easily read this file via a view log type button. They should also be able to resume from where they left off, using what has been logged. I'm trying to decide if I should: > > a) Save the variables to a .mat file using save ... -append. Then generate an easy to read file when the use clicks. > > b)Save the variables to a .m file, then parse the data if loaded. > > I'm thinking I should go with saving the variables to .mat file, but am wondering if anyone knows of performance issues this way. Is saving a .mat file slower than writing a text file and vice-versa? I'm going to run some tests for now; but if anyone knows of the best ways to create logs that would be appreciated. > > Thanks One more question, if I do append, is there anyway to have -append not overwrite the current variable. I need the log to store the same variables at each iteration.
From: Walter Roberson on 11 Jun 2010 14:48 Adam wrote: > One more question, if I do append, is there anyway to have -append not > overwrite the current variable. I need the log to store the same > variables at each iteration. No, there isn't, just as there is no way in load() to specify which occurrence of a particular variable that you want.
From: Adam on 11 Jun 2010 16:23 Walter Roberson <roberson(a)hushmail.com> wrote in message <huu0ha$oh1$1(a)canopus.cc.umanitoba.ca>... > Adam wrote: > > > One more question, if I do append, is there anyway to have -append not > > overwrite the current variable. I need the log to store the same > > variables at each iteration. > > No, there isn't, just as there is no way in load() to specify which occurrence > of a particular variable that you want. Ok, I'm thinking I should actually stick with creating a .m file. I'm trying to use fprintf to format it but I'm having some trouble. I would like something like this. Say h1 is a matrix containing [2.5 3.5 4.5] and the other are single values. iteration h1 h2 1 2.5 8 3.5 4.5 2 3.5 8 4.5 6.5 .... Is fprintf the easiest way to do it or should I try dlmwrite? The problem with dlm write is h1 is not the same dimension as the other variables.
From: Walter Roberson on 11 Jun 2010 17:12 Adam wrote: > Ok, I'm thinking I should actually stick with creating a .m file. I'm > trying to use fprintf to format it but I'm having some trouble. I would > like something like this. Say h1 is a matrix containing [2.5 3.5 4.5] > and the other are single values. > > iteration h1 h2 1 2.5 8 > 3.5 > 4.5 > > 2 3.5 8 > 4.5 6.5 > ... > > Is fprintf the easiest way to do it or should I try dlmwrite? The > problem with dlm write is h1 is not the same dimension as the other > variables. That format is not compatible with a .m file, as .m files are expected to be Matlab code. The format would be usable for text files, but unless you use a fixed number of positions for each column, reading the data in nicely will be tricky. I think fprintf is likely to be the easiest for your situation. On the other hand, in your situation I would seriously consider constructing character arrays as strings, finding the longest one and padding the others with blanks to match the size, then concatenating that together and writing that out. Ignoring the iteration variable for the moment, h1str = num2str(h1(:), '%4.1f '); h2str = num2str(h2(:), '%4.2f\n'); h1len = numel(h1); h2len = numel(h2); h1pad = max(0,h2len-h1len); h2pad = max(0,h1len-h2len); h1str = vertcat(h1str, repmat(' ', h1pad, size(h1str,2))); h2str = vertcat(h2str, repmat(' ', h2pad, size(h2str,2))); fwrite(FID, horzcat(h1str, h2str))
|
Pages: 1 Prev: Matrix manipulation Next: linear constraint question |