plot repeating x values
8 ビュー (過去 30 日間)
古いコメントを表示
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?
0 件のコメント
回答 (2 件)
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 件のコメント
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
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Annotations についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!