Matrix, struct, array, comparison

1 回表示 (過去 30 日間)
Francesco
Francesco 2014 年 2 月 22 日
編集済み: Tim leonard 2014 年 3 月 12 日
I have two struct variable: primo and secondo
>> primo
primo =
Y: {1x8 cell}
primo.Y
ans =
Columns 1 through 4
[1000x9 double] [1000x9 double] [1000x9 double] [1000x9 double]
Columns 5 through 8
[1000x9 double] [1000x9 double] [1000x9 double] [1000x9 double]
secondo =
Y: {1x8 cell}
>> secondo.Y
ans =
Columns 1 through 4
[1000x9 double] [1000x9 double] [1000x9 double] [1000x9 double]
Columns 5 through 8
[1000x9 double] [1000x9 double] [1000x9 double] [1000x9 double]
Inside of these two variables, there should be the same numerical values. But I do not know if it is really so. How can I be sure that the numerical value inside the matrix [1000x9double] are exactly the same for each matrix? Thanks.

採用された回答

Mischa Kim
Mischa Kim 2014 年 2 月 22 日
Francesco, loop through the eight cells and use isequal to compare the matrices.
  1 件のコメント
Francesco
Francesco 2014 年 2 月 22 日
Perfect. It's very useful command. Good! Thanks.

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

その他の回答 (1 件)

Tim leonard
Tim leonard 2014 年 3 月 12 日
編集済み: Tim leonard 2014 年 3 月 12 日
Mischa's answer is perfectly valid. Just wanted to share some code.
all(cellfun(@(x,y)(all(x==y)),primo,secondo))
note, primo and secondo need to be same length, so check that before checking inside the cell.

カテゴリ

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