Borrar filtros
Borrar filtros

How to change xlim to specific range only?

5 visualizaciones (últimos 30 días)
ramya
ramya el 6 de Ag. de 2024
Comentada: dpb el 7 de Ag. de 2024
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 comentario
dpb
dpb el 6 de Ag. de 2024
xlim, ylim set limits but specific ticks are via xticks, yticks. datatip does what it says it does...

Iniciar sesión para comentar.

Respuestas (2)

dpb
dpb el 6 de Ag. de 2024
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 comentarios
Walter Roberson
Walter Roberson el 7 de Ag. de 2024
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 el 7 de Ag. de 2024
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

Iniciar sesión para comentar.


Walter Roberson
Walter Roberson el 6 de Ag. de 2024
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)

Categorías

Más información sobre Just for fun en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by