[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: exporting matrix to txt
From: |
Andy Buckle |
Subject: |
Re: exporting matrix to txt |
Date: |
Fri, 18 Jun 2010 14:25:02 +0100 |
On Fri, Jun 18, 2010 at 1:51 PM, Erika Bueno <address@hidden> wrote:
> Hello, guys!
>
> You've already explained me how I can work with matrices. Now I can
> read an image and store it like a matrix.
>
> Is there a way to export this matrix as a TXT file like this: line,
> column and the value inside the cell?
>
> Thanks!
>
> Erika
-----------------file: save_var_coords.m --------------------
function save_var_coords(filename,matrix2d)
% TODO: check input is 2D matrix
fid=fopen(filename,'w'); % TODO: check for io errors
for r=1:rows(matrix2d)
for c=1:columns(matrix2d)
fprintf(fid,'row: %i col: %i val:%.4f
\r\n',r,c,matrix2d(r,c))
end
end
fclose(fid);
end
----------------------------------------------------------
>a=[1 2;3 4];
>save_var_coords('a.txt', a)
>system("type a.txt");
row: 1 col: 1 val:1.0000
row: 1 col: 2 val:2.0000
row: 2 col: 1 val:3.0000
row: 2 col: 2 val:4.0000
I assume you are on windows. You may want '\n' rather than '\r\n'
depending on what apps will read the file.
--
/* andy buckle */
- exporting matrix to txt, Erika Bueno, 2010/06/18
- Re: exporting matrix to txt, Jordi Gutiérrez Hermoso, 2010/06/18
- Re: exporting matrix to txt, Erika Bueno, 2010/06/18
- Re: exporting matrix to txt, Jordi Gutiérrez Hermoso, 2010/06/18
- Re: exporting matrix to txt, Erika Bueno, 2010/06/18
- Re: exporting matrix to txt, Jordi Gutiérrez Hermoso, 2010/06/18
- Re: exporting matrix to txt, Erika Bueno, 2010/06/18
- Re: exporting matrix to txt, Jordi Gutiérrez Hermoso, 2010/06/18
- Message not available
- Re: exporting matrix to txt, Jordi Gutiérrez Hermoso, 2010/06/18
- Re: exporting matrix to txt, Vincent Letocart, 2010/06/18
Re: exporting matrix to txt,
Andy Buckle <=