[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: How to convert mesh data in octave to Gnuplot data file
From: |
Marc Normandin |
Subject: |
Re: How to convert mesh data in octave to Gnuplot data file |
Date: |
Thu, 18 Sep 2008 00:57:31 -0400 |
User-agent: |
Thunderbird 2.0.0.16 (X11/20080724) |
pauljoseph wrote:
>
>
> Marc Normandin wrote:
>> Does something like
>>
>> [x,y] = meshgrid (1:size(z,1), 1:size(z,2))
>>
>> do what you want?
>>
>>
>
> Hi Marc,
> I tried using meshgrid, but I still need to "reshape" the matrix, but then
> when I write to file, I need some breaklines. I didn't how to do it but
> manually.
>
> This is what I have done.
> z=[0,0,0;0,1,0;0,0,0];
> x=[1,2,3];
> y=[1,2,3];
> [XX,YY]=meshgrid(x,y);
> gpX=reshape(XX,9,1);
> gpY=reshape(YY,9,1);
> gpZ=reshape(z,9,1);
>
> [gpX,gpY,gpZ]=
> 1 1 0
> 1 2 0
> 1 3 0
> 2 1 0
> 2 2 1
> 2 3 0
> 3 1 0
> 3 2 0
> 3 3 0
> dlmwrite('test.dat',[gpX,gpY,gpZ],'\t');
>
> So ya, this is almost what I want, but when I write to text file, I need
> break lines among the blocks, the desired output in the text file should be
> 1 1 0
> 1 2 0
> 1 3 0
>
> 2 1 0
> 2 2 1
> 2 3 0
>
> 3 1 0
> 3 2 0
> 3 3 0
This is ugly but it should work.
z = [0 0 0; 0 1 0; 0 0 0];
[nr, nc] = size (z);
fid = fopen ('test.dat', 'a');
for ii = 1:nr
for jj = 1:nc
fprintf (fid, '%d\t%d\t%d\n', ii, jj, z(ii,jj));
if jj == nc
fprintf (fid, '\n');
end
end
end
fclose (fid);
Perhaps someone can think of a cleaner (or built-in) way to accomplish
the same.
--
------------------------------------------------------------------
Marc D. Normandin http://web.ics.purdue.edu/~mdnorman
Graduate Research Assistant address@hidden
Indiana University School of Medicine 317-278-9841 (tel)
Department of Radiology, Division of Research 317-274-1067 (fax)
------------------------------------------------------------------