plot repeating x values

11 Ansichten (letzte 30 Tage)
Christopher Tran Rojas
Christopher Tran Rojas am 21 Okt. 2020
Kommentiert: Ameer Hamza am 21 Okt. 2020
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?

Antworten (2)

Ameer Hamza
Ameer Hamza am 21 Okt. 2020
Bearbeitet: Ameer Hamza am 21 Okt. 2020
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 Kommentare
Christopher Tran Rojas
Christopher Tran Rojas am 21 Okt. 2020
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 am 21 Okt. 2020
Check the updated code.

Melden Sie sich an, um zu kommentieren.


Robert U
Robert U am 21 Okt. 2020
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

Kategorien

Mehr zu 2-D and 3-D Plots finden Sie in Help Center und File Exchange

Tags

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by