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: Fri, 20 Nov 2015 06:52:43 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.3.0

Am 12.11.2015 um 08:02 schrieb Sebastian Schöps:
karl wrote
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?
No. You will always need two iterations to evaluate all combinations of x
and y. However, these loops can be vecorized if your function allows it. In
your case it seems that only one of the two loops can be vectorized.

Please consider that the input of your function is a 11-by-22-MATRIX if you
try to vectorize both loops. Thus the following does not make sense (it
assumes that x is a 2-by-1 vector):

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

if you do not believe me, ask Octave:

function fr = frame1 (x)
size(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-tp4673436p4673448.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
I have found now the solution. With "vec" one can transform the matrices X and Y into vectors, one can calcuulate the function
values with one command and then getting  the matrix  form of the function values with 
"reshape".



reply via email to

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