plot repeating x values

조회 수: 8 (최근 30일)
Christopher Tran Rojas
Christopher Tran Rojas 2020년 10월 21일
댓글: Ameer Hamza 2020년 10월 21일
I have 2 vectors
m =
[0.05
0.06
0.08
0.10
0.15
0.25
0.35
0.45
0.35
0.25
0.15
0.10
0.08
0.06
0.05];
and
d = [
0.0340
0.0390
0.0495
0.0565
0.0735
0.0995
0.1205
0.1465
0.1270
0.1040
0.0760
0.0590
0.0510
0.0420
0.0360];
When I use plot(m,d) I get 2 overlapping lines. How do I get the plot showing the x axis from .05 to .45 to .05 symetrically instead of overlapping?

답변 (2개)

Ameer Hamza
Ameer Hamza 2020년 10월 21일
편집: Ameer Hamza 2020년 10월 21일
For that, you will need to modify the m-vector
[~, idx] = max(m);
m(idx+1:end) = 2*m(idx)-m(idx+1:end);
ax = axes();
plot(m, d);
ax.XTick = 0.05:0.1:0.85;
ax.XTickLabel = [0.05:0.1:0.45 0.35:-0.1:0.05];
  댓글 수: 2
Christopher Tran Rojas
Christopher Tran Rojas 2020년 10월 21일
Thank You, but the x axis is showing 0 to .9 instead of 0 up to .45 and back to 0.
[~, idx] = max(m);
m(idx+1:end) = 2*m(idx)-m(idx+1:end);
plot(m,d,'-x')
grid on
Ameer Hamza
Ameer Hamza 2020년 10월 21일
Check the updated code.

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


Robert U
Robert U 2020년 10월 21일
Hi Christopher Tran Rojas,
you have to replace the xTickLabel-Strings. Otherwise an increasing value vector is expected. Plus, you have to take into account that your x-axis-values are not equally distributed.
m = [0.05 0.06 0.08 0.10 0.15 0.25 0.35 0.45 0.35 0.25 0.15 0.10 0.08 0.06 0.05];
d = [0.0340 0.0390 0.0495 0.0565 0.0735 0.0995 0.1205 0.1465 0.1270 0.1040 0.0760 0.0590 0.0510 0.0420 0.0360];
plotVecX = m-max(m);
plotVecX([false diff(plotVecX)<0]) = -plotVecX([false diff(plotVecX)<0]);
fh = figure;
ah = axes(fh);
plot(ah,plotVecX,d);
ah.XMinorGrid = 'on';
ah.XGrid = 'on';
ah.YMinorGrid = 'on';
ah.YGrid = 'on';
xTickVec = ah.XTick;
xTickVec(xTickVec>0) = -xTickVec(xTickVec>0);
xTickVec = xTickVec + max(m);
ah.XTickLabel = cellfun(@num2str,num2cell(xTickVec),'UniformOutput',false)';
Kind regards,
Robert

카테고리

Help CenterFile Exchange에서 Annotations에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by