Info

Questa domanda è chiusa. Riaprila per modificarla o per rispondere.

Plot from 2 matrixes as x value and 1 matrix as y

1 visualizzazione (ultimi 30 giorni)
Fredrik Preus Dovland
Fredrik Preus Dovland il 21 Set 2020
Chiuso: MATLAB Answer Bot il 20 Ago 2021
Ok, so I have 2 cell-arrays:
Time{} = 1x4249
The time format is: HH:MM
Date{} = 1x4249
The date format is: dd.mm.yyyy
They corresponds to each other and the lasts 7 days. In addition to those arrays I have another matrix for available parking spots thoughout 7 days:
parking[] = 1x4249
My task is to plot 180 values from parking for each Xtick which is eaqual to 6 hours from the time cell. On the labels of the plot I have to include both the date and time at the x-axis and the avalability at the y-axis.
I am pretty new to Matlab so i would really appreciate help, and if the description was a little confusing I apologize.
  3 Commenti
David Hill
David Hill il 21 Set 2020
Should not be difficult. Please provide a sample of what your data looks like. What have you done so far?
Fredrik Preus Dovland
Fredrik Preus Dovland il 21 Set 2020
So far i have:
y=[jernbanen_num];
x=[str];
plot(y)
set(gca,'xticklabel',x.')
Where "jernbanen_num" is the matrix containing available parking spots and "str" is a combined cell-array of the time and date

Risposte (1)

Seth Furman
Seth Furman il 21 Ott 2020
1) It is simpler and more efficient to store durations and datetimes in a duration or datetime array respectively instead of a cell array.
Assuming Time is a cell array of durations and Date is a cell array of datetimes, we can convert them as follows.
Time = [Time{:}];
Date = [Date{:}];
2) As the name implies, datetime arrays can store date AND time information, so we can combine Date and Time.
Date = Date + Time;
Date.Format = 'dd.MM.yyyy hh:mm';
3) Datetimes can be plotted directly with our data.
Assuming parking is an array of doubles, we can plot them as follows.
plot(Date,parking)
Please refer to the following page in the documentation for more information.
4) Capitalization matters when setting the format of a datetime or duration.
The format "dd.mm.yyyy" refers to days, minutes, and years. In fact we probably want "dd.MM.yyyy", which refers to days, months, and years.
Please refer to the documentation for datetime for more information.

Questa domanda è chiusa.

Community Treasure Hunt

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

Start Hunting!

Translated by