help-octave
[Top][All Lists]
Advanced

[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:47:50 +0100

OK. you will definitely want to make that '\n' at the end of the
format string, then.

also, FWIW,
system('cat a.txt');
is a quick way to see the file from octave

On Fri, Jun 18, 2010 at 2:38 PM, Erika Bueno <address@hidden> wrote:
> 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 */
>>
>



-- 
/* andy buckle */



reply via email to

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