How to check if all the data in the cell array are the same?
51 ビュー (過去 30 日間)
古いコメントを表示
There is a variable called 'data'
in a cell array of 1x10
{100} {100} {100} {100} {100} {100} {100} {100} {100} {100} 100 has the same value.
How can I return these 10 data to True or False?
isequal(data(1),data(2),data(3),data(4),data(5),data(6),data(7),data(8),data(9),data(10))
Instead of writing down all the elements like this, I want to make sure that all the data in th
e cell array has the same value even if the size of the cell array changes.
0 件のコメント
回答 (3 件)
Stephen23
2022 年 3 月 21 日
編集済み: Stephen23
2022 年 3 月 21 日
The simple and very efficient MATLAB approach is to use a comma-separated list:
Avoid approaches which join the data together (e.g. CELL2MAT) or that change data type (e.g. to STRING): they are inefficient, fragile, and will fail for arrays of incompatible sizes, types, or due to loss of information when converting type.
C = repmat({10},1,9)
X = isequal(C{:})
C{1} = 10+eps(10)
X = isequal(C{:})
0 件のコメント
Chunru
2022 年 3 月 21 日
c = {100, 100, 100, 200} % cell array
cm = cell2mat(c);
same = all(cm == cm(1))
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Cell Arrays についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!