From: Sriram on
Hi,
I am having a problem with increasing the resolution of my 3-d plot. I have pasted the code below. If I try to increase the mesh density, then Av and delta also need to increase, but they can't increase in the for loop for some reason.
Please help

close all
clear all
x=[1:15];
y=[1:15];
[X,Y] = meshgrid(x,y);
for Av=1:15
for delta=1:15
ip2(Av,delta)=abs(0.6313628160e-3*Av*(6500000000.*delta*Av+9999999997.*delta+0.1300000000e11*Av+0.2000000000e11)/(0.3202734676e11*delta+0.2754525644e11*delta*Av-0.2818058868e11*Av+4372862683.*delta*Av^2-0.1831738265e11*Av^2));
end
end
iip3=10*log10(ip2/0.001);
figure;
surf(X,Y,iip3);
From: Walter Roberson on
Sriram wrote:
> Hi,
> I am having a problem with increasing the resolution of my 3-d plot. I
> have pasted the code below. If I try to increase the mesh density, then
> Av and delta also need to increase, but they can't increase in the for
> loop for some reason.

Please clarify what you mean about them not being able to increase in the for
loop? If you are talking about changing the value of Av or Delta once you are
already in the for loops, then No, you cannot do that. But there is no
indication in the code of you trying to do that.

> x=[1:15];
> y=[1:15];
> [X,Y] = meshgrid(x,y);
> for Av=1:15
> for delta=1:15

Possibly there you want

for Av = 1:length(x)
for delta = 1:length(y)

That's another interpretation of your remark about not being able to increase
them -- if you didn't want their limits to be hardcoded.

> ip2(Av,delta)=abs(0.6313628160e-3*Av*(6500000000.*delta*Av+9999999997.*delta+0.1300000000e11*Av+0.2000000000e11)/(0.3202734676e11*delta+0.2754525644e11*delta*Av-0.2818058868e11*Av+4372862683.*delta*Av^2-0.1831738265e11*Av^2));
>
> end
> end

I suggest you use bsxfun() to execute that all at once over all Av and delta
values without 'for' loop.

ip2 = bsxfun( @(Av,delta)
abs(0.6313628160e-3*Av*(6500000000.*delta.*Av+9999999997.*delta+0.1300000000e11.*Av+0.2000000000e11)/(0.3202734676e11.*delta+0.2754525644e11.*delta.*Av-0.2818058868e11.*Av+4372862683.*delta.*Av.^2-0.1831738265e11.*Av.^2)),
x.', y);

Notice the transpose on x there.

> iip3=10*log10(ip2/0.001);
> figure;
> surf(X,Y,iip3);
From: Sriram on
I want to have this 3d plot with a finer resolution which means instead of just integral values from 1 to 15, i need to plot the function even for values of Av and delta for 1.2,1.3 etc. The FOR loop doesnt allow me to do it and gives me an error saying

"Attempted to access ip2(1,1.1); index must be a positive integer or logical."

Also my matlab is unable to recognize bsxfun. Is there any other alternative way to do it?

Thanks

Walter Roberson <roberson(a)hushmail.com> wrote in message <hujkql$11q$1(a)canopus.cc.umanitoba.ca>...
> Sriram wrote:
> > Hi,
> > I am having a problem with increasing the resolution of my 3-d plot. I
> > have pasted the code below. If I try to increase the mesh density, then
> > Av and delta also need to increase, but they can't increase in the for
> > loop for some reason.
>
> Please clarify what you mean about them not being able to increase in the for
> loop? If you are talking about changing the value of Av or Delta once you are
> already in the for loops, then No, you cannot do that. But there is no
> indication in the code of you trying to do that.
>
> > x=[1:15];
> > y=[1:15];
> > [X,Y] = meshgrid(x,y);
> > for Av=1:15
> > for delta=1:15
>
> Possibly there you want
>
> for Av = 1:length(x)
> for delta = 1:length(y)
>
> That's another interpretation of your remark about not being able to increase
> them -- if you didn't want their limits to be hardcoded.
>
> > ip2(Av,delta)=abs(0.6313628160e-3*Av*(6500000000.*delta*Av+9999999997.*delta+0.1300000000e11*Av+0.2000000000e11)/(0.3202734676e11*delta+0.2754525644e11*delta*Av-0.2818058868e11*Av+4372862683.*delta*Av^2-0.1831738265e11*Av^2));
> >
> > end
> > end
>
> I suggest you use bsxfun() to execute that all at once over all Av and delta
> values without 'for' loop.
>
> ip2 = bsxfun( @(Av,delta)
> abs(0.6313628160e-3*Av*(6500000000.*delta.*Av+9999999997.*delta+0.1300000000e11.*Av+0.2000000000e11)/(0.3202734676e11.*delta+0.2754525644e11.*delta.*Av-0.2818058868e11.*Av+4372862683.*delta.*Av.^2-0.1831738265e11.*Av.^2)),
> x.', y);
>
> Notice the transpose on x there.
>
> > iip3=10*log10(ip2/0.001);
> > figure;
> > surf(X,Y,iip3);
From: Walter Roberson on
Sriram wrote:
> Also my matlab is unable to recognize bsxfun. Is there any other
> alternative way to do it?

Which Matlab release do you have? If you have R14 or later, then see
http://www.mathworks.com/matlabcentral/fileexchange/23005
for a substitute bsxfun


> I want to have this 3d plot with a finer resolution which means instead
> of just integral values from 1 to 15, i need to plot the function even
> for values of Av and delta for 1.2,1.3 etc. The FOR loop doesnt allow
> me to do it and gives me an error saying
>
> "Attempted to access ip2(1,1.1); index must be a positive integer or
> logical."
>

for avidx = 1:length(x)
Av = x(avidx);
for deltaidx = 1:length(y)
delta = y(deltaidx);
ip2(avidx, deltaidx) = ....
end
end
From: Sriram on
Thanks for the help. This worked.

Walter Roberson <roberson(a)hushmail.com> wrote in message <hujnit$4su$1(a)canopus.cc.umanitoba.ca>...
> Sriram wrote:
> > Also my matlab is unable to recognize bsxfun. Is there any other
> > alternative way to do it?
>
> Which Matlab release do you have? If you have R14 or later, then see
> http://www.mathworks.com/matlabcentral/fileexchange/23005
> for a substitute bsxfun
>
>
> > I want to have this 3d plot with a finer resolution which means instead
> > of just integral values from 1 to 15, i need to plot the function even
> > for values of Av and delta for 1.2,1.3 etc. The FOR loop doesnt allow
> > me to do it and gives me an error saying
> >
> > "Attempted to access ip2(1,1.1); index must be a positive integer or
> > logical."
> >
>
> for avidx = 1:length(x)
> Av = x(avidx);
> for deltaidx = 1:length(y)
> delta = y(deltaidx);
> ip2(avidx, deltaidx) = ....
> end
> end