Creating a custom axis

조회 수: 24 (최근 30일)
John Carroll
John Carroll 2022년 10월 31일
댓글: Voss 2022년 11월 1일
I am looking to create a custom x axis for a 3D surface plot. My x data has a form similar to V = [0 5 10 15 20 15 10 5 0 -5 -10 -15 -20 -15 -10 -5 0]. Each point will have a corrosponding y and z point. When I plot them how ever the similar x points overlap since they have the same value. I would like to make the x axis use the values in the matrix without overlap but instead writing them in the order they appear in the matrix. If possible I'd like to preserve the numerical value without converting to text.
Currently I create a variable for the x axis V similar to above. In the surafce plat I Use V instead of T as I show below. But this causes one have of the data to be graphed over the other half. I then created a linear matrix of datat points from 1 to 161 and used that at the x axis. This works and I get the graph I am looking for however the x axis label is wrong. I would like to force the axis to use V. To do this I tried to convert to a string and label the x axis with it. QualityFactor is a matrix of size 200x161 and FreqS is of size 200x1. When I graph this I get the following
The graph axis forces itself to 200 points along the x axis. To correct this I force the axis to 161 to match the size of the data and I get the following
In the first case I get the axis I want but the data is compressed and doesn't fill the axis. When I force the axis I get the size plot I want but the axis is cut off and doesn't rescale to match the data.
How might I fix this issue?
Thank you
VoltMax = 200;
VoltStep = 5;
VSD = VoltMax/VoltStep;
V = VoltStep*[0:VSD VSD-1:-1:-VSD -VSD+1:-1 0]; V will be a 1x161 matrix
T=1:1:161;
Vt=string(V);
surf(T, FreqS, QualityFactor)
xticklabels({Vt(1),Vt(41),Vt(81),Vt(121),Vt(161)})

채택된 답변

Voss
Voss 2022년 10월 31일
Set the xticks when you set the xticklabels (xticklabels by itself doesn't set the locations of the ticks, just their labels). And probably set the xlim as well.
VoltMax = 200;
VoltStep = 5;
VSD = VoltMax/VoltStep;
V = VoltStep*[0:VSD VSD-1:-1:-VSD -VSD+1:-1 0];
T=1:1:161;
surf(T, linspace(0,20,200), rand(200,161)) % random data for demo
xticks(T(1:VSD:end))
xticklabels(string(V(1:VSD:end)))
xlim(T([1 end]))
view(2)
  댓글 수: 2
John Carroll
John Carroll 2022년 10월 31일
This works perfectly thank you
Voss
Voss 2022년 11월 1일
You're welcome!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

태그

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by