Borrar filtros
Borrar filtros

Change date from cell to number inside array

1 visualización (últimos 30 días)
Yassin Wahby
Yassin Wahby el 21 de Mayo de 2024
Comentada: Yassin Wahby el 22 de Mayo de 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 comentario
Steven Lord
Steven Lord el 21 de Mayo de 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.)

Iniciar sesión para comentar.

Respuesta aceptada

Stephen23
Stephen23 el 21 de Mayo de 2024
Editada: Stephen23 el 21 de Mayo de 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 comentarios
Stephen23
Stephen23 el 21 de Mayo de 2024
Editada: Stephen23 el 21 de Mayo de 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 el 22 de Mayo de 2024
I tried it again but I used the bracket incorrectly, which caused the error. It works perfectly now, thank you.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Calendar en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by