From: ben harper on 17 May 2010 13:47 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 17 May 2010 14:11 "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 17 May 2010 14:17 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 17 May 2010 14:25 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 17 May 2010 15:04
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 |