help-octave
[Top][All Lists]
Advanced

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

Re: Function of vector with meshgrid and surf


From: karl
Subject: Re: Function of vector with meshgrid and surf
Date: Thu, 12 Nov 2015 06:18:09 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.3.0

Am 12.11.2015 um 00:26 schrieb Sebastian Schöps:
karl wrote
I have a small problem with the syntax.
...
How do I have to modify the line "Z=frame([X,Y])" that the surf command
works and gives the surface?
X and Y are matrices (in your case 11x11) and [X,Y] is even 11x(2*11). Your
functions expects vectors and thus it does not work properly. You either
have to modify "frame" to allow matrix input or you have to loop over the
entries. Here are three possibilities:

function karl
        x1=0:0.1:1;
        [X,Y]=meshgrid(x1,x1);

        Z=frame_modified(X,Y);
        figure;
        surf(X,Y,Z);
        
        for i=1:size(Z,1)
                Z(i,:)=frame([X(i,:); Y(i,:)]);
        end
        figure;
        surf(X,Y,Z);

        for i=1:size(Z,1)
                for j=1:size(Z,1)
                        Z(i,j)=frame([X(i,j); Y(i,j)]);
                end
        end
        figure;
        surf(X,Y,Z);
        
end

function fr = frame_modified (x,y)
        fr=x+y;
endfunction

function fr = frame (x)
fr=x(1,:)+x(2,:);
endfunction



--
View this message in context: 
http://octave.1599824.n4.nabble.com/Function-of-vector-with-meshgrid-and-surf-tp4673436p4673444.html
Sent from the Octave - General mailing list archive at Nabble.com.

_______________________________________________
Help-octave mailing list
address@hidden
https://lists.gnu.org/mailman/listinfo/help-octave
Hallo Sebastian thanks for the answer, BUT:
I can't modify frame as I wrote already, since then I have to change many other 
things, and I would like
to avoid looping. Let us consider a simpler case:

function fr = frame1 (x)
fr=x(1)+x(2);
endfunction

Is it possible in this case, i.e. with no modification of frame1, to avoid 
looping?

Ciao
Karl



reply via email to

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