Visualy change values of legend

3 views (last 30 days)
Eren Atar
Eren Atar on 14 Jun 2022
Answered: Steven Lord on 14 Jun 2022
Hello,
x = [1:288];
y = rand(288,1);
plot(x,y);
xlabel('time in 5 min')
ylabel('random numbers')
title('24/5 over a day')
As seen I got 288 Values on x and on the x legend it also goes from 0 -300.
I want the x axis to only show me visualy the values from 0-24 without changing any values on the y axis.
Every 12 elements on x it should show me a +1.
Like switching the "Values"
Current What I want
12 1
24 2
36 3
48 4
60 5
72 6
... ...
288 24
  1 Comment
Image Analyst
Image Analyst on 14 Jun 2022
Not sure what you want, but try legend or ylim

Sign in to comment.

Answers (2)

Star Strider
Star Strider on 14 Jun 2022
Edited: Star Strider on 14 Jun 2022
Possibly —
x = [1:288];
y = rand(288,1);
plot(x,y);
xlabel('time in 5 min')
ylabel('random numbers')
title('24/5 over a day')
xlim([min(x) max(x)])
Ax = gca;
xt = Ax.XTick;
Ax.XTickLabel = fix(xt*(5/60)); % Scale By 5 min Intervals / 60 minutes
EDIT — (14 Jun 2022 at 13:10)
To get the x-axis ticks to display 12-hour increments as requested, change the XTick increment and the XTickLabel assignment:
x = [1:288*7]; % Increase To 7 Days
y = rand(288*7,1);
plot(x,y);
xlabel('time in 5 min')
ylabel('random numbers')
title('24/5 over a day')
xlim([min(x) max(x)])
hour12 = 60*12/5; % 12-Hour Increment
Ax = gca;
Ax.XTick = x(1:hour12:end); % X-Tick Values
Ax.XTickLabel = floor(Ax.XTick * 5/(60*12)); % X-Tick Labels
% XTickVals = buffer(Ax.XTick * 5/(60*12),7) % Information
.
  2 Comments
Image Analyst
Image Analyst on 14 Jun 2022
Maybe just divide by 5 before plotting
x = [1:288];
y = rand(288,1);
plot(x/5,y);
xlabel('time in 5 min')
ylabel('random numbers')
title('24/5 over a day')

Sign in to comment.


Steven Lord
Steven Lord on 14 Jun 2022
x = [1:288];
y = rand(288,1);
plot(x,y);
xlabel('time in 5 min')
ylabel('random numbers')
title('24/5 over a day')
tickLocations = 12:12:288;
xticks(tickLocations)
xticklabels(string(tickLocations/12))
Once you've changed the tick labels your X label is at best misleading, so I'd change that to 'time (hours)' or something similar.

Tags

Products


Release

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by