help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: exporting matrix to txt


From: Erika Bueno
Subject: Re: exporting matrix to txt
Date: Fri, 18 Jun 2010 10:38:08 -0300

Thanks, Andy! I'm gonna try this. I'm using ubuntu.

:)

2010/6/18 Andy Buckle <address@hidden>:
> 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 */
>



reply via email to

[Prev in Thread] Current Thread [Next in Thread]