From: ben harper on
Hello,
I want to convert a mat file to text file
but when i convert with this code:

clc
clear
load('file.mat')
Conten=who;
save('file.txt',Conten{:},'-ascii')

It saves only values.
It doesn't save variable names.
How can i save it?
thank you
From: us on
"ben harper" <controlusc(a)gmail.com> wrote in message <hsrveo$qq0$1(a)fred.mathworks.com>...
> Hello,
> I want to convert a mat file to text file
> but when i convert with this code:
>
> clc
> clear
> load('file.mat')
> Conten=who;
> save('file.txt',Conten{:},'-ascii')
>
> It saves only values.
> It doesn't save variable names.
> How can i save it?
> thank you

can you show a small example of your input/output(?)...

us
From: Walter Roberson on
ben harper wrote:

> I want to convert a mat file to text file
> but when i convert with this code:
>
> clc
> clear
> load('file.mat')
> Conten=who;
> save('file.txt',Conten{:},'-ascii')
>
> It saves only values.
> It doesn't save variable names.
> How can i save it?

Do you want to save *only* the variable names, or *only* the values, or do you
want to save both? If both, then how should the names appear relative to the
values?

You are probably going to need to use fprintf(), but if your variables might
contain cell arrays or structures or objects or symbolic objects or function
handles or inline functions, then outputting those can get a little messy.
From: ben harper on
Walter Roberson <roberson(a)hushmail.com> wrote in message <hss18c$ole$1(a)canopus.cc.umanitoba.ca>...
> ben harper wrote:
>
> > I want to convert a mat file to text file
> > but when i convert with this code:
> >
> > clc
> > clear
> > load('file.mat')
> > Conten=who;
> > save('file.txt',Conten{:},'-ascii')
> >
> > It saves only values.
> > It doesn't save variable names.
> > How can i save it?
>
> Do you want to save *only* the variable names, or *only* the values, or do you
> want to save both? If both, then how should the names appear relative to the
> values?
>
> You are probably going to need to use fprintf(), but if your variables might
> contain cell arrays or structures or objects or symbolic objects or function
> handles or inline functions, then outputting those can get a little messy.

my values are scalar or vectoral.
there is not any cell array or structure.

mat file has both the variable names and values.
i want to save them to a text file like:

mass = 12
velocity= 4
From: Walter Roberson on
ben harper wrote:

> my values are scalar or vectoral.
> there is not any cell array or structure.
>
> mat file has both the variable names and values.
> i want to save them to a text file like:
>
> mass = 12
> velocity= 4

for K = 1:length(Conten)
thisval = eval(Conten{K});
sprintf(['%s =', repmat(' %g', 1, length(thisval)), '\n'], Conten{K},
thisval(:) .');
end