f



writing cell containing text and matrix to a text file

Is there a way to write a cell containing text and numerical matrix to
a text file?

I have the following:

values = [1 2 3 4 5 6 7 8 9 10];
cellA={'nameA', values};%this is the cell containing the text and
matrix
cellA =
    'name'    [1x10 double]


So that the text file row would look something like:

nameA 1 2 3 4 5 6 7 8 9 10

Ultimately, I would like to be able to append this with cellB, cellC,
etc (all same format as shown above).

I tried both dlmwrite and xlswrite without much success.  Is there a
way to do this?

Thanks!
0
beginner
5/21/2010 7:34:22 PM
comp.soft-sys.matlab 211266 articles. 23 followers. lunamoonmoon (257) is leader. Post Follow

2 Replies
1463 Views

Similar Articles

[PageSpeed] 44

Here is an example:

values = [1 2 3 4 5 6 7 8 9 10];
cellA={'nameA', values};%this is the cell containing the text and

myfile = fopen('myfile.txt','w'); % open file
fprintf (myfile, cellA{1});
for lc=1:length(cellA{2})
    fprintf (myfile, [' ' num2str(cellA{2}(lc))]);
end
fprintf (myfile,'\r\n'); % next line
fclose(myfile);

-----------------------------------------
Maxim Vedenev, MATLAB Custom Programming
vedenev@ngs.ru
http://simulations.narod.ru/
0
vedenev
5/22/2010 6:52:43 AM
On May 21, 11:52=A0pm, vedenev <vedenev.ma...@gmail.com> wrote:
> Here is an example:
>
> values =3D [1 2 3 4 5 6 7 8 9 10];
> cellA=3D{'nameA', values};%this is the cell containing the text and
>
> myfile =3D fopen('myfile.txt','w'); % open file
> fprintf (myfile, cellA{1});
> for lc=3D1:length(cellA{2})
> =A0 =A0 fprintf (myfile, [' ' num2str(cellA{2}(lc))]);
> end
> fprintf (myfile,'\r\n'); % next line
> fclose(myfile);
>
> -----------------------------------------
> Maxim Vedenev, MATLAB Custom Programming
> vede...@ngs.ruhttp://simulations.narod.ru/

Very helpful.  Is there a way to make a "tab" after the cellA{1}? So
that there is a "tab" in the file between the string and numbers.
Seems like I can add a new line:       fprintf (myfile,
'\t');            but I was wondering if it could be included in the
first line:  fprintf (myfile, cellA{1});%somewhere in here?  I have
tried multiple different things without success.
0
beginner
5/23/2010 6:48:49 PM
Reply: