How to find specified data in table by reffers

1 回表示 (過去 30 日間)
Arif
Arif 2024 年 2 月 6 日
コメント済み: Arif 2024 年 2 月 6 日
What function that i can use to extract data in table by reference ? for example, i want to extract cell (3,4) to be a 1x1 double. But it must be specified by another cell data. For this case, I want to know the 'period' when 'stepnum' is 3. Thanks

採用された回答

Dinesh
Dinesh 2024 年 2 月 6 日
編集済み: Dinesh 2024 年 2 月 6 日
Hello Arif,
To extract a specific cell from a table in MATLAB by reference to another cell's data, you can use logical indexing. For your example, to find the 'Period' when 'StepNum' is 3, here's a sample code:
% Loaded table is assumed to be 'Periodandfrequencies'
% First, find the row where 'StepNum' is 3
row = Periodandfrequencies.StepNum == 3;
% Then, extract the 'Period' from that row
periodValue = Periodandfrequencies.Period(row);
periodDouble = double(periodValue);
Here's a simplified 1 line code that also handles the case where the value for column "StepNum" is a string in single quotes:
periodWhenStepNumIsThree = Periodandfrequencies.Period(strcmp(Periodandfrequencies.StepNum, '3'));
The following documentation link might also help you:
  8 件のコメント
Stephen23
Stephen23 2024 年 2 月 6 日
Of course you can use a text comparison function e.g. STRCMP or MATCHES or similar:
etc.
Arif
Arif 2024 年 2 月 6 日
thank you so much for your help @Dinesh
thanks also for the reference @Stephen23

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGet Started with MATLAB についてさらに検索

タグ

製品


リリース

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by