Clear Filters
Clear Filters

Change date from cell to number inside array

1 view (last 30 days)
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 Comment
Steven Lord
Steven Lord on 21 May 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.)

Sign in to comment.

Accepted Answer

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

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!