Azzera filtri
Azzera filtri

Change date from cell to number inside array

1 visualizzazione (ultimi 30 giorni)
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 Commento
Steven Lord
Steven Lord il 21 Mag 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.)

Accedi per commentare.

Risposta accettata

Stephen23
Stephen23 il 21 Mag 2024
Modificato: Stephen23 il 21 Mag 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 Commenti
Stephen23
Stephen23 il 21 Mag 2024
Modificato: Stephen23 il 21 Mag 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 il 22 Mag 2024
I tried it again but I used the bracket incorrectly, which caused the error. It works perfectly now, thank you.

Accedi per commentare.

Più risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by