How to plot peaks on desired location in a 3D plot?

There are two vectors that will make an xy-plane. I want to draw a peak pointing in z-direction on a desired location on the xy-plane. In code form it is:
x=linspace(0,180,100);% 1st vector
y=x;% 2nd vector
Now I want to draw a peak of strenght 5 on the intersection of the point (x1,y1)=(30,50).Likewise, I want to draw another peak on the intersection of the point (x2,y2)=(40,120). Further, I want to draw another peak on the intersection of the point (x3,y3)=(60,140). But this whole plot should be a 3D plot as shown in the attached image.

2 件のコメント

Matt J
Matt J 2022 年 2 月 21 日
What determines the z-valeus everywhere where there isn't a peak?
Sadiq Akbar
Sadiq Akbar 2022 年 2 月 21 日
Thank you for your response. There is no eq. but I want to draw peaks of my desired values. Say for example, one peak should be of height 5, another should be of height 5.5 and another should be of height 7.

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

 採用された回答

Star Strider
Star Strider 2022 年 2 月 21 日

1 投票

[X,Y] = ndgrid(0:300);
C = 50:100:300;
Zf = @(C) exp(-(((X-C).^2)*0.5+((Y-C).^2)));
Z = Zf(C(1)) + Zf(C(2)) + Zf(C(3));
[pks,locs] = findpeaks(Z(:), 'MinPeakHeight',0.5)
pks = 3×1
1 1 1
locs = 3×1
15101 45301 75501
figure
surf(X, Y, Z, 'EdgeColor','none')
hold on
plot3(X(locs), Y(locs), Z(locs), '^r')
hold off
Experiment with your data with this approach.
.

8 件のコメント

Sadiq Akbar
Sadiq Akbar 2022 年 2 月 22 日
Thank you very much dear Star Strider for your response. Indeed I want like this but here you have used some function for z and in my case I have no function but just a vector like z=[1.2e-8 3.5e-7 7.1e-9] and I want to draw a line for its 1st element (i.e., 1.2e-8) on a point (x1,y1)=(30,50) located on xy-plane similar to yours or similar to the one in the attached image. Likewise, I want to draw another line on another point (x2,y2)=(70,120) on xy-plane for the 2nd element of vector z(i.e., 3.5e-7). And in the same fashion I want to draw another line for the 3rd element of vector z(i.e., 7.1e-9) on a point (110,210) on xy-plane.
Star Strider
Star Strider 2022 年 2 月 22 日
I cannot understand that.
Where do each one of the lines start and end?
Are the lines supposed to be vertical, and from 0 through each peak?
(The surf or surfc function plots a matrix. How that matrix is created it not relevant.)
Sadiq Akbar
Sadiq Akbar 2022 年 2 月 22 日
Thank you very much dear Star Strider. The line will start from just the xy-plane as you have done in your code or as in attached image.Yes, these lines will be vertical as in atached image above. Yes, you are right that surf and surfc functions plot a matrix and I don't have matrix. That's the problem, so I asked it here.
Star Strider
Star Strider 2022 年 2 月 22 日
I do not understand that you don’t have the matrix.
To just plot the points as lines use the stem3 function, with the surfc plot, or by itself.
x1y1 = [ 30 50 1.2E-8];
x2y2 = [ 70 120 3.5E-7];
x3y3 = [110 210 1.7E-9];
xymtx = [x1y1; x2y2; x3y3]; % Concatenate Into Vector
figure
stem3(xymtx(:,1), xymtx(:,2), xymtx (:,3), 'Marker','none', 'LineWidth',2)
grid on
set(gca, 'ZScale','log') % Logarithmic Z-Axis ()ptional)
Use the hold function to add the lines to the surfc plot.
Change the properties of the stem3 plot to get the desired result.
.
Sadiq Akbar
Sadiq Akbar 2022 年 3 月 2 日
I am extremely sorry for bein late.Thank you very much dear Star Strider for your help. Indeed I want like this.But in given plot the limits of x and y-axes are different while I want their limits the same i.e., limits of both of them must be from 0 to 180. Can we do this change in given figure while keeping all the three lines plots undisturbed? Further, I am not getting it: "Use the hold function to add the lines to the surfc plot". What do you mean by this?
Star Strider
Star Strider 2022 年 3 月 2 日
The axes ranges can be limited —
x1y1 = [ 30 50 1.2E-8];
x2y2 = [ 70 120 3.5E-7];
x3y3 = [110 210 1.7E-9];
xymtx = [x1y1; x2y2; x3y3]; % Concatenate Into Vector
figure
stem3(xymtx(:,1), xymtx(:,2), xymtx (:,3), 'Marker','none', 'LineWidth',2)
grid on
set(gca, 'ZScale','log') % Logarithmic Z-Axis (Optional)
xlim([0 180])
ylim([0 180])
However, with the axes limited this way, ‘x3y3’ is no longer visible because it plots beyond the limits.
.
Sadiq Akbar
Sadiq Akbar 2022 年 3 月 2 日
Thank you very much dear Star Strider for your help.
Star Strider
Star Strider 2022 年 3 月 2 日
As always, my pleasure!

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeGeographic Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by