Effacer les filtres
Effacer les filtres

Change date from cell to number inside array

1 vue (au cours des 30 derniers jours)
Yassin Wahby
Yassin Wahby le 21 Mai 2024
Commenté : Yassin Wahby le 22 Mai 2024
I have data inside an array including strings and dates. The times appear to be in a cell inside the array.
The times appear from 0 to 1, which I understand. This data is brought from Excel which I must use.
The problem is I want to do an if statement inside this array to see which entries are larger than 10pm (approximately 0.9).
Whenever I try and use an if statement, I get an error because the times are stored in a cell format inside the array. How do I change it from a cell to a numeric format I can use?
  1 commentaire
Steven Lord
Steven Lord le 21 Mai 2024
How did you get this data into MATLAB? As @Stephen23 suggested in a comment, I think storing this data in a table array rather than a cell array would make analyzing your data much easier. Take a look at the readtable function.
If you need to customize how readtable imports your data either have MATLAB tell you the options it would use to read the data (using the detectImportOptions function) or use the Import Tool to interactively experiement with the options. If you use Import Tool you could tell MATLAB to import the data and/or generate code to use to import the data (if you have many files in the same format to import.)

Connectez-vous pour commenter.

Réponse acceptée

Stephen23
Stephen23 le 21 Mai 2024
Modifié(e) : Stephen23 le 21 Mai 2024
" How do I change it from a cell to a numeric format I can use?"
Use the correct type of indexing:
if itin_full{1,6}>=0.9
% ^ ^
You need to learn the two ways to index cell arrays:
  • {} curly braces refer to the cell content.
  • () parentheses refer to the cell array itself
  3 commentaires
Stephen23
Stephen23 le 21 Mai 2024
Modifié(e) : Stephen23 le 21 Mai 2024
"So I need to know how to turn a number in a cell it into a numerical value that can support mathematical operations
You can access the content of the cell array (e.g. your numeric scalars) using curly-brace indexing, exactly as I showed you in my answer. Did you try doing that?
Tip: it looks like a table would be a much better way of storing your data.
Yassin Wahby
Yassin Wahby le 22 Mai 2024
I tried it again but I used the bracket incorrectly, which caused the error. It works perfectly now, thank you.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Calendar dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by