how to create surface plot during each time calculation for several times?

Greeting to instructors:
I tried to create 6 surface plots, 2 plots each time. The coding logic is below:
XP=linspace(0,1,50); YP=linspace(0,1,50); [X,Y]=meshgride(XP,YP);
for i=1:3
----
A1=some function of X and Y, A2=another function form of X and Y;
figure
mesh(X,Y,A1)
figure
mesh(X,Y,A2)
end
MatLab gives me 6 figures without curves in it.
I modify my code to another form, using subplot command, as below
XP=linspace(0,1,50); YP=linspace(0,1,50); [X,Y]=meshgride(XP,YP);
for i=1:3
----
A1=some function of X and Y, A2=another function form of X and Y;
subplot(3,2,2*i-1)
mesh(X,Y,A1)
subplot(3,2,2*i)
mesh(X,Y,A2)
end
this time, Matlab gives me 2 plots without curve in it. Could you teach me how to create 6 correct figures. Your kindly helps will be deeply appreciated. With best regards,
Donyau

Answers (1)

It is likely that your X or your Y or your A1 and A2 are empty or consist of a single point.
If you are using division in your formula, make sure you use ./ instead of / as the operator.

3 Comments

Dear Mr. Roberson,
I may mislead you. I decide to uncover my code using the number, as below.
% direct Fresnel technique, established date: June 25, 2016
close all;
clear all;
% **************** start coding *****************
% define the calculated parameters
r0=3.; z0=[15. 20. 30.]; nod=256.; vn1=length(z0); % number of z0
for i=1:vn1
if(r0/z0(i) < 0.08)
L=10.*r0;
else
vp1=ceil(z0(i)/(r0*0.075)); L=vp1*r0;
end
du=1./L; det=L/nod;
xyp=(-nod/2.:floor((nod-1)/2.))*det; % set up 1-D axis points
[xp,yp]=meshgrid(xyp,xyp); % set up coordinate axis in aperture plane
% build up a circular aperture characteristics as circle function
vn2=find(sqrt(xp.*xp+yp.*yp) <= r0);
A1=zeros(nod); A1(vn2)=ones(size(vn2));
FA1=fftshift(fft2(A1));
% set reciprocal coordinate
uv=(-nod/2.:floor((nod-1.)/2.))*du;
[u,v]=meshgrid(uv,uv); % set 2-D reciprocal coordinate
vn5=find(sqrt(u.*u+v.*v) <= 1.); B1=zeros(nod,nod); B1(vn5)=ones(size(vn5));
Ac=FA1.*B1; % FFT for t(x,y)
sgz=sqrt(ones(nod)-u.*u-v.*v); % argument of transfer function
% sgz=sigmaz, u=sgx, v=sgy
% ***** calculate the phi functions for polarization effects *****
fxx=(ones(nod)+sgz-u.*u)./((ones(nod)+sgz).*sqrt(sgz));
fxz=-u./sqrt(sgz);
A2=(Ac.*fxx).*exp(2.*pi*i*z0(i)*sgz);
A3=ifft2(A2); A4=A3.*conj(A3); % intensity= f*conj(f)
figure
mesh(xp(89:169,89:169),yp(89:169,89:169),A4(89:169,89:169))
A5=(Ac.*exp(2.*pi*i*z0(i)*sgz)).*fxz;
A5=ifft2(A5); A6=A5.*conj(A5); % intensity= f*conj(f)
figure
mesh(xp(89:169,89:169),yp(89:169,89:169),A6(89:169,89:169))
end
Then, the X,Y, A4, and A6 are NOT empty or consist of single point. I used the correct writing to do the matrix manipulation. The MatLab also gives me 6 plot frames but not curve in them. Could you teach me what commands I need to use? Thank for your helps in advances. Regards,
All of your A6 is infinite. This is due to your A5 being quite large, on the order of 10^214 or more in the real and imaginary parts.
Not all of your A4 is infinite, but all of the part that is selected for plotting is.
The first 4 plots look okay to me when I try.
Dear Mr. Roberson, If I used z0=15, I can have the results. If I used z=20 and have the result. I used z=30, I also can have result. But if I try to use "for" command to calculate all three results at the same time. I do not know how to do it because the MatLab gives me the 6 frames, but no curve in the frame. That means I can obtain the all results when I calculate three times, but I can not obtain all results at one time. I think I use the wrong plot command --figure. What is the correct command do I use? The attached file is all calculated results of A4 and A6 for z0=15, 20, and 30. They are not infinite. I just want to know how to obtain all three results at one time. regards, Donyau

This question is closed.

Asked:

on 26 Jun 2016

Closed:

on 20 Aug 2021

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!