Input Dates from an excel sheet without getting a NaN

A
Hi there, I would like to input Column A and Plot it against Column F however I get the error message that values must be an integer.
M= readmatrixFilename
Date= M(:,0)
*error*
maxHeight = M(:,4)
Is there a way to inform matlab that M(:,0) is Date/Time data without it spitting out an error and therefore being able to plot the max wave height from 01/04/2021-31/03/2022
Apologies I asked something similar previously as can be seen above.
Thanks in advance

Réponses (1)

Voss
Voss le 2 Mai 2022
Modifié(e) : Voss le 2 Mai 2022
M(:,0) would refer to the 0th column of M, but indexing in MATLAB starts at 1. There is no 0th column, so that's why you get that error message (which specifies positive integer). It's not because of Date/Time data. Try:
Date = M(:,1)
and see what that gives you.
Related:
maxHeight = M(:,5)

2 commentaires

Ah that helps, although when I then plot it,
plot (M(:,1),M(:,5)
My X axis which should be date is a numeric value of 4.425x10^4, how would I format that to say 01 Apr etc
I would try
Date = datetime(M(:,1))
and use that to plot instead of M(:,1). But the value you report (4.425x10^4) doesn't seem like it would correspond to any date near 31/03/2022, so I don't know for sure.
Maybe upload the file (using the paperclip button) if you continue to have trouble.

Connectez-vous pour commenter.

Catégories

Produits

Version

R2022a

Commenté :

le 2 Mai 2022

Community Treasure Hunt

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

Start Hunting!

Translated by