
From:  Zilore Mumba 
Subject:  Re: Using otpiminterp in octave 
Date:  Wed, 8 Oct 2014 11:41:07 +0200 
Dear Zilore,
as xi is an matrix and not an array you must use numel to get its total number of elements like this:
for i = 1:numel(xi),fprintf(fid, '%5.2f %5.1f %5.1f\n', xi(i),yi(i),obsi(i) );
endforthis is equivalent to the following whish make it more clear that xi, yi and obsi are arrays:for j = 1:size(xi,2),for i = 1:size(xi,1),fprintf(fid, '%5.2f %5.1f %5.1f\n', xi(i,j),yi(i,j),obsi(i,j) );endforendforOr without loops (which is generally faster):results = [xi(:) yi(:) obs(:)];save ascii result.txt resultI hope this helps,
AlexOn Wed, Oct 8, 2014 at 8:33 AM, Zilore Mumba <address@hidden> wrote:_______________________________________________Thanks Doug,This takes me closer. That code snippet gives me the x, y, z arrangement as I want but it stops after doing one value of x (18) and the corresponding values of y.Now I need a way to go back in the loop and take the successive values of x.On Tue, Oct 7, 2014 at 11:47 PM, Doug Stewart <address@hidden> wrote:On Tue, Oct 7, 2014 at 5:37 PM, Zilore Mumba <address@hidden> wrote:Further help sought. With the kind help I got so far I do get the correct interpolated values.% put x, y, z into a matrix beofre printing
Being a complete beginner in octave, I have been going through documentation and tried several ways of writing formatted output without success. I would like my output to be printed as x, y, z
%result of interpolatin
obsi = fi + mean_obs;matxy = [xi yi obsi];
fid = fopen('mydata.txt','w');
fprintf(fid, '%5.2f %5.1f %5.1f\n', xi,yi,obsi);
%for j = 1:length(yi),
% for i = 1:length(xi),
% fprintf(fid, '%5.2f %5.1f %5.1f\n', matxy);
% end
%end
fclose(fid);try thisfor i = 1:length(xi),fprintf(fid, '%5.2f %5.1f %5.1f\n', xi(i),yi(i),obsi(i) );
endforThe two fprintf statements give me all x, followed by all y then all z values.The for loop gives me only 121 values, the length of the individual vectors x, y, z.I know after a long time of trying and browsing documentation, I may get. But to save time I would appreciate someone's time to help me out.On Tue, Oct 7, 2014 at 6:12 PM, Zilore Mumba <address@hidden> wrote:Thanks very much, I did not see that silly slip I made. Now I get the results I expect. The assistance is highly appreciated.On Tue, Oct 7, 2014 at 5:19 PM, Doug Stewart <address@hidden> wrote:On Tue, Oct 7, 2014 at 10:55 AM, Zilore Mumba <address@hidden> wrote:Thanks Ben, Doug for pointing me in the right direction. I get the error below. Initially I had put [xi,yi] = ndgrid((22:0.1:34,18:0.1:8); When I removed the minus on 22 (i.e. [xi,yi] = ndgrid((22:0.1:34,18:0.1:8);) the error is pointing at 22.
While am still trying to see if I can see the right format in the documentation, Iwould appreciate further assistance.
octave:1> example_optiminterp_data
parse error near line 16 of file /home/zmumba/Optiminterp/example_optiminterp_data.m
syntax error
>>> [xi,yi] = ndgrid((22:0.1:34,18:0.1:8);
^You have 2 (( and only need 1 (On Tue, Oct 7, 2014 at 2:46 PM, Doug Stewart <address@hidden> wrote:On Tue, Oct 7, 2014 at 8:30 AM, Ben Abbott <address@hidden> wrote:
On Oct 7, 2014, at 8:09 AM, Zilore Mumba <address@hidden> wrote:
> The data I used is as in the attached file
>
> Just to be sure I read in the data as per lines below:
>Gold Coast Pipe Band
> % load the data file
> data=""> >
> % the 1st and 2nd column represent the location
> x = data(:,1);
> y = data(:,2);
> % the 3rd column represents the observations to interpolate
> obs = data(:,3);
>
>
> The output I get has no similarity with the input. Am not sure if am printing the error field.
>
> On Mon, Oct 6, 2014 at 11:21 PM, Doug Stewart <address@hidden> wrote:
>
>
> On Mon, Oct 6, 2014 at 1:01 PM, Zilore Mumba <address@hidden> wrote:
> I have just installed octave on ubuntu. Trying the example "example_optiminterp_data.m" with my own data, I get very strange values (very small values) see extract of output below
>
> # Created by Octave 3.8.1, Mon Oct 06 17:02:39 2014 CAT <address@hidden>
> # name: fi
> # type: matrix
> # rows: 41
> # columns: 41
> 6.046732358407388e147 2.165934319425287e147 7.689701072432262e148 2.705909551864099e148 9.437495202085344e149 3.262419987996825e149 1.117796281402676e149 3.795990593671885e150 1.277695255495584e150 4.262546577144117e151
>
> Here is the line I added for the output
> save mydata.txt fi;
>
> suspect am not printing the correct results.
> I apologise for this very basic question
> Help will be appreciated
> Zilore Mumba
The ranges for (x,y) and (xi,yi) do not overlap.
min (x)
ans = 23.100
max(x)
ans = 33.200
min (y)
ans = 17.800
max (y)
ans = 8.9000
[xi,yi] = ndgrid(2:0.1:2,2:0.1:2);
should this be:[xi,yi] = ndgrid(22:0.1:34,18:0.1:8);Try adding
xi = median (x) + xi;
yi = median (y) + yi;
Ben
Helpoctave mailing list
address@hidden
https://lists.gnu.org/mailman/listinfo/helpoctave
[Prev in Thread]  Current Thread  [Next in Thread] 