How to do if condition on the type of data

3 ビュー (過去 30 日間)
Behrooz Daneshian
Behrooz Daneshian 2022 年 12 月 30 日
回答済み: Walter Roberson 2022 年 12 月 30 日
Hi all,
I want to creat if condition in MATLAB in a way that if type of my data is cell, do something and else, do something else. I know that type of data can be determined using class(data). Would you please guide me in this regard?

採用された回答

Walter Roberson
Walter Roberson 2022 年 12 月 30 日
%preparation
if rand() < 0.5
C = 23;
else
C = {23, 'skidoo'};
end
%now we need to know the type of C to progress
if iscell(C)
disp('was cell')
output = C{1} * 2;
else
disp('was not cell')
output = C(1) * 2;
end
was cell
output
output = 46

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeStructures についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by