I want to have the time (e.g from january to december) on the x-axis and just location on the "y axis". Example:
LOCATION
location 1 x_________ x
location 2 x __ x
location 3 x x_xx__xxx__xxx
timline jan ---- juni ---- dec --- > 2016

 Réponse acceptée

Star Strider
Star Strider le 20 Jan 2017

0 votes

See if something like this does what you want:
dnv = datenum([2016 01 00]) + cumsum(eomday(2016, 1:12)); % X-Axis Dates
loc1 = datenum([2016 01 01]) + randi(364, 1, 3); % Create Data
loc2 = datenum([2016 01 01]) + randi(364, 1, 5); % Create Data
loc3 = datenum([2016 01 01]) + randi(364, 1, 7); % Create Data
figure(1)
plot(loc1, 3*ones(size(loc1)), 'x')
hold on
plot(loc2, 2*ones(size(loc2)), 'x')
plot(loc3, 1*ones(size(loc3)), 'x')
hold off
grid
set(gca, 'XTick', dnv)
datetick('x', 'mmm', 'keepticks')
axis([xlim 0 4])

4 commentaires

Star Strider
Star Strider le 23 Jan 2017
kk1991’s Comment moved here:
Yes, thank you. But is it possible to get locations on the y-axis and not number?
This works:
dnv = datenum([2016 01 00]) + cumsum(eomday(2016, 1:12)); % X-Axis Dates
loc1 = datenum([2016 01 01]) + randi(364, 1, 3); % Create Data
loc2 = datenum([2016 01 01]) + randi(364, 1, 5); % Create Data
loc3 = datenum([2016 01 01]) + randi(364, 1, 7); % Create Data
figure(1)
plot(loc1, 3*ones(size(loc1)), 'x')
hold on
plot(loc2, 2*ones(size(loc2)), 'x')
plot(loc3, 1*ones(size(loc3)), 'x')
hold off
grid
set(gca, 'XTick', dnv)
datetick('x', 'mmm', 'keepticks')
axis([xlim 0 4])
ytlblstr = sprintf('Location %d\n', 3:-1:1);
ytlbls = regexp(ytlblstr, '\n', 'split');
ytlbls{end} = 'LOCATIONS';
set(gca, 'YTick',1:length(ytlbls), 'YTickLabel',ytlbls)
You can plot the straight lines within the hold block by specifying the x-range and a vector of ones. For example, to plot a line between 15 Mar and 12 May for Location 1, this will work:
plot([datenum([2016 03 15]) datenum([2016 05 12])], 3*[1 1])
Note: ‘Location 1’is y=3, ‘Location 2’ is y=2, ‘Location 3’ is y=1.
Experiment with my code to get the result you want.
kk1991
kk1991 le 2 Fév 2017
Thank you so much! :)
Star Strider
Star Strider le 2 Fév 2017
My pleasure!
If my Answer helped you solve your problem, please Accept it!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Christmas / Winter dans Centre d'aide et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by