How plot a figure like this attached figure?

Hi,
I have some laser beam amplitude profile and I want to plot this profiles like follow fig in matlab.
dsds1.jpg
infact, I have tried this codes
% z1 and z2 are defined in my script as 500*500 matrix
r1=linspace(0,0.005,500);
r2=r1;
mesh(r1,r2,z1)
hold on
mesh(r1,r2,z2+2)
but I can not rotate and it not give what I want. I need help?

 採用された回答

J. Alex Lee
J. Alex Lee 2020 年 2 月 2 日
編集済み: J. Alex Lee 2020 年 2 月 2 日

0 投票

It's because mesh expects z-data to be actual coordinates in z, but mesh (and surf) will accept a 4th argument for color
N = 500;
r1=linspace(0,0.005,N);
[X,Y] = meshgrid(r1);
figure; cla; hold on;
ax = gca;
% fig = figure;
% ax = axes(fig,'NextPlot','add');
for i = 1:10
C = rand(N); % replace with the image
Z = ones(N)*i;
% flip the order of Y and Z to get vertical slices
s = surf(ax,X,Z,Y,C,'EdgeColor','none');
end
ax.DataAspectRatio = [1,700,1] % stretch the "z"-axis view
% rotate the view
view([-65,14])

6 件のコメント

Habib
Habib 2020 年 2 月 2 日
Dear Lee, thanks for your replying and attention.
I tried your code and got following error:
"Error using axes
Incorrect input args for
constructing axes object"
I could not to fix it. What must I do?
J. Alex Lee
J. Alex Lee 2020 年 2 月 2 日
that's odd...are you adapting my example to your code and that is failing? Or are you running my example as is and it is failing?
what is your matlab version? does the edited version of code above work?
Habib
Habib 2020 年 2 月 2 日
I only run your example as is.
my matlab version is 2015rb.
J. Alex Lee
J. Alex Lee 2020 年 2 月 2 日
and what happens if you try the edited version above?
Habib
Habib 2020 年 2 月 2 日
I will run your code in 2017rb version. After, I will insert the result as comment.
Habib
Habib 2020 年 2 月 2 日
Dear Alex, Thank You so much.
Your code correctly work .

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

質問済み:

2020 年 2 月 2 日

コメント済み:

2020 年 2 月 2 日

Community Treasure Hunt

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

Start Hunting!

Translated by