From: Aman on
i have a function abc=XYZ(N,k,R,eta); for example...
its gives p=N*R^eta/k;
q=N^eta/k*r;

now k, R and eta are constant.
N=[10 20 30 40];
for i=1:4
abc=XYZ(N(i),1,8,4);
O(i)=p;
S(i)=q;
plot(N(i),S(i),'*')
hold on;
axis([0 250 199 200])
grid on;
subplot(2,1,2)
plot(N(i),O(i),'*')
axis([25 225 4 6])
end
but it gives me this output with error msg....
N =
10 20 30 40
p=
4.6607e+008
q =
199.6330
??? Undefined function or variable 'p'.

Error in ==> aman at 5
O(i)=p;


what i want to do that store all the four values of p and q for different N,in O and S, and plot a graph of N,O and N,S.
From: Frédéric Bergeron on

> i have a function abc=XYZ(N,k,R,eta); for example...
> its gives p=N*R^eta/k;
> q=N^eta/k*r;
>
> now k, R and eta are constant.
> N=[10 20 30 40];
> for i=1:4
> abc=XYZ(N(i),1,8,4);
> O(i)=p;
> S(i)=q;

> ??? Undefined function or variable 'p'.
>
> Error in ==> aman at 5
> O(i)=p;

Hi,

I think you may want to define more explicity the outputs of your XYZ function.
In the loop, the function call would probably work better if it is:
for i=1:4
[p,q]=XYZ(N(i),1,8,4);
O(i)=p;
S(i)=q;
[..]

that way, when you store your p and q values in O and S you will have explicity defined them by the output [p,q] of your function. If you do not do that Matlab don't find any variable named p or q in your main script.

Fred
From: dpb on
Aman wrote:
> i have a function abc=XYZ(N,k,R,eta); for example...
> its gives p=N*R^eta/k;
> q=N^eta/k*r;
>
> now k, R and eta are constant.
> N=[10 20 30 40];
> for i=1:4
> abc=XYZ(N(i),1,8,4);
> O(i)=p;
> S(i)=q;

But, while your function may internally compute p,q it isn't returning
them. You need the function to look something like

function [p,q] = XYZ(N,k,R,eta);

as well as any other outputs wanted...not sure what abc was intended to
be; maybe it should be

function [abc,p,q] = XYZ(N,k,R,eta);

Again, no way to tell what you really intend...

....

> what i want to do that store all the four values of p and q for
> different N,in O and S, and plot a graph of N,O and N,S.

I'd suggest restructuring the function to vectorize it so it would
return the arrays -- meshgrid might be useful for the 2D nature over N,R

--