How to plot data with two different X- axis in a single plot?

4 ビュー (過去 30 日間)
Vishnuvardhan Naidu Tanga
Vishnuvardhan Naidu Tanga 2021 年 9 月 21 日
コメント済み: Star Strider 2021 年 9 月 23 日
Hello all,
I am trying to plot a data of multiple plots in a single graph. I am facing a problem in plotting it. I need the data from different Y axis in a single axis bar i.e, im my case it is from -200:200. And for X axis I need a scale for each and every X axis data as the data varies for every Y axis data. Along with that I need to plot the data with an offset at different location and i also need the offset distance as a scale either on top or on bottom X axis. I have tried plotting it but I am unable to retrive the desired result. Can someone please help me. My code is:
Z = readtable('Atq100_2.xlsx') ;
data = table2array(Z) ;
plot(data(:,2)+10, data(:,1),'linewidth', 2);
hold on
plot(data(:,4)+250, data(:,3),'linewidth', 2);
hold on
plot(data(:,6)+500, data(:,5),'linewidth', 2);
hold on
plot(data(:,8)+1000, data(:,7),'linewidth', 2);
hold on
plot(data(:,10)+1500, data(:,9),'linewidth', 2);
hold off
legend('x=10mm', 'x=250mm', 'x=500mm', 'x=1000mm', 'x=1500mm', 'Location', 'northeastoutside');

採用された回答

Star Strider
Star Strider 2021 年 9 月 21 日
One option is to use the subplot function in a loop —
Z = readtable('https://www.mathworks.com/matlabcentral/answers/uploaded_files/745434/Atq100_2.xlsx') ;
data = table2array(Z) ;
plot(data(:,2)+10, data(:,1),'linewidth', 2);
hold on
plot(data(:,4)+250, data(:,3),'linewidth', 2);
hold on
plot(data(:,6)+500, data(:,5),'linewidth', 2);
hold on
plot(data(:,8)+1000, data(:,7),'linewidth', 2);
hold on
plot(data(:,10)+1500, data(:,9),'linewidth', 2);
hold off
legend('x=10mm', 'x=250mm', 'x=500mm', 'x=1000mm', 'x=1500mm', 'Location', 'northeastoutside');
N = size(data,2);
Nsp = N/2;
ttlc = {'x=10mm', 'x=250mm', 'x=500mm', 'x=1000mm', 'x=1500mm'};
figure
for k = 1:Nsp
subplot(1,Nsp,k)
col = [2 1]+2*(k-1);
plot(data(:,col(1)), data(:,col(2)), 'LineWidth',2)
grid
title(ttlc{k})
ylim([-1 1]*200)
end
I am not certain what the desired result is.
.
  8 件のコメント
Vishnuvardhan Naidu Tanga
Vishnuvardhan Naidu Tanga 2021 年 9 月 23 日
Thank you so much. It looks more like the desired result i need. I am glad and thankful for your help.
Star Strider
Star Strider 2021 年 9 月 23 日
As always, my pleasure!
.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLegend についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by