How to change xlim to specific range only?

4 ビュー (過去 30 日間)
ramya
ramya 2024 年 8 月 6 日
コメント済み: dpb 2024 年 8 月 7 日
a=xlsread('output1.xlsx','final graph');
xaxis=0:9;
yaxis=a(:,2);
yaxis1=a(:,3);
yaxis=a(:,4);
yaxis2=a(:,5);
figure
plot(xaxis,yaxis)
hold on
plot(xaxis,yaxis1)
hold on
plot(xaxis,yaxis2)
how to change xlim to specific to 0 :3:9 ylim to 30:30:300 how to insert data tips or markers at each point of xaxis
  1 件のコメント
dpb
dpb 2024 年 8 月 6 日
xlim, ylim set limits but specific ticks are via xticks, yticks. datatip does what it says it does...

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

回答 (2 件)

dpb
dpb 2024 年 8 月 6 日
a=readmatrix('output1.xlsx','Sheet','final graph'); % xlsread has been deprecated
cols2plot=[2:5]; % indices to columns wanting to plot
x=[0:height(a)-1]; % generalize instead of hardcoding magic numbers
hL=plot(x,a(:,cols2plot)); % plot is vectorized by columns; no need for repeating
XL=0; XH=9; XT=3; % limits, tick delta -- as data, not code
YL=30; YH=300; YT=30;
xlim([XL XH]); ylim([YL YH])
xticks([XL:XT:XH]); yticks([YL:YT:YH]);
grid on
  3 件のコメント
Walter Roberson
Walter Roberson 2024 年 8 月 7 日
xticks([0,3,5,9])
Unless you mean something like
text([0,3,5,9], a([1 4 6 10],cols2plot), ["0", "3", "5", "9"])
dpb
dpb 2024 年 8 月 7 日
a=readmatrix('output1.xlsx','Sheet','final graph'); % xlsread has been deprecated
cols2plot=[2:5]; % indices to columns wanting to plot
x=[0:height(a)-1]; % generalize instead of hardcoding magic numbers
hL=plot(x,a(:,cols2plot)); % plot is vectorized by columns; no need for repeating
XL=0; XH=9; XT=3; % limits, tick delta -- as data, not code
YL=30; YH=300; YT=30;
xlim([XL XH]); ylim([YL YH])
xticks([XL:XT:XH]); yticks([YL:YT:YH]);
grid on
% add data tips although there's very little room
% this does the requested positions in X for the first line requested to be
% plotted; adding for the other lines would write over these...you don't
% have sufficient room for that much data on the plot...the location at 0
% is off the defined y-axis limits so doesn't show...
TX=[0 3 5 9];
for i=1:numel(TX)
%disp([i TX(i) find(x==TX(i)) a(x==TX(i),cols2plot(1))])
datatip(hL(1),TX(i),a(x==TX(i),cols2plot(1)));
end

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


Walter Roberson
Walter Roberson 2024 年 8 月 6 日
how to change xlim to specific to 0 :3:9 ylim to 30:30:300
That is not possible. xlim() expects to be passed a limit method (such as "tight") or a limit mode (such as "manual"), or a two-element vector of type single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | categorical | datetime | duration
Under no circumstances will xlim accept the four element vector [0 3 6 9] which is what 0:3:9 would request.
You can ask for
xticks(0:3:9)

カテゴリ

Help Center および File ExchangeJust for fun についてさらに検索

タグ

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by