|
"Ben " <basburywvu.nospam@hotmail.com> wrote in message
<fr8hi2$b2m$1@fred.mathworks.com>...
> In my code I build a structure in a for loop using dynamic
> field names from a cell array of strings containing the
> variable names. I then use the save function with the
> -struct option to save each field as its own variable.
> However, I just found out that I have to make my m-code
> backwards compatible with Matlab 6.5 which does not have
> this option. I am trying to avoid using sprintf's and
eval's
> but I am running out of ideas.
>
> Below is a pseudo example of what I am doing. Note: In
> reality the calculation in the for loop is a lot more
complex.
>
> varNames = {'name1','name2','name3','nameN'};
> for i = 1:length(varNames)
> dataStruct.(varNames{i}) = rand(5,1);
> end
> save('myMatFile.mat','-struct','dataStruct')
>
> What would be the best way to recreate the results without
> using the save -struct and avoiding the eval function if
> possible.
Hi Ben
TO tell the truth, i rarely use save cause of the
inconvenience. Here recommend you to use the new mexload
and mexsave created by myself. You do not need to create
the struct any more and you can use it either in matlab
2007+ or 6.5.
Here is the example.
mexsave(filename, 'w', 'name1', rand(5,1), 'name2', rand
(5,1), ....);
Enjoy.
the link is
http://rapidshare.com/files/97196537/loadsave.rar.jpg.html
and pls save it to loadsave.rar.
It includes mexsave, mexload and mexdelete.
|