Change date from cell to number inside array

8 ビュー (過去 30 日間)
Yassin Wahby
Yassin Wahby 2024 年 5 月 21 日
コメント済み: Yassin Wahby 2024 年 5 月 22 日
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 件のコメント
Steven Lord
Steven Lord 2024 年 5 月 21 日
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.)

サインインしてコメントする。

採用された回答

Stephen23
Stephen23 2024 年 5 月 21 日
編集済み: Stephen23 2024 年 5 月 21 日
" 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 件のコメント
Stephen23
Stephen23 2024 年 5 月 21 日
編集済み: Stephen23 2024 年 5 月 21 日
"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 2024 年 5 月 22 日
I tried it again but I used the bracket incorrectly, which caused the error. It works perfectly now, thank you.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeData Type Identification についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by