Date: Mar 14, 2013 8:01 AM
Author: Phil
Subject: Re: Save strings and numbers together
"Bruce " <blmckinley@signalprocessing.com> wrote in message <khprk6$c5d$1@newscl01ah.mathworks.com>...

> "Phil Roberts" wrote in message <khpl27$nat$1@newscl01ah.mathworks.com>...

> > Hi,

> >

> > I have the following strings and number as separate variables. How can I save them together in one file, such as a .txt file?

> >

> > Strings

> > 'Test Point'

> > 'speed_Engine_av'

> > 'torque_Brake_av'

> > 'power_Brake_av'

> >

> > Numbers

> > 1

> > 2

> > 3

> > 4

> >

> > I wish to save them so that the string and its corresponding number are on the same row i.e. Test Point 1, speed_Engine_av 2 etc

> >

> > Thanks in advance,

> >

> > Phil

>

> As long as the strings don't include any commas, you can use a Comma Separated Value file. You can open the file as a spreadsheet and the cells will appear in separate columns. Or you can open it and fscanf your values back into MATLAB or using any other programming language.

>

> strvar = {'Test Point', 'speed_Engine_av'. 'torque_Brake_av', 'power_Brake_av'};

> val = {1, 2, 3, 4};

> fid=fopen('myfile.csv','wt');

> for i=1:length(val)

> fprintf(fid,'%s, %d\n',strvar{i},val{i});

> end

> fclose(fid);

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Thanks for the response.

If I have I have an additional column of numbers in the "val" parameter, how to I add this to fprintf so both columns of val are printed in the file? I am a new user of matlab so apologies for the simipicity of this question.

Thanks in advance,

Phil