Matriz dimension issue, a version issue?

1 回表示 (過去 30 日間)
Ame ZL
Ame ZL 2019 年 4 月 12 日
回答済み: Walter Roberson 2019 年 4 月 12 日
Hello everyone,
I have made a function that includes some normalization
It works perfect for me in my R2018a version.
However a friend is finding problems on her 2015b.
The line goes by
GLCM=GLCM./sum(sum(GLCM));
where GLCM is a 32x32x4
the error is " Matrix dimensions must agree "
Could this be a version issue? or what are we missing?
Thanks very much

採用された回答

Walter Roberson
Walter Roberson 2019 年 4 月 12 日
Yes, it is a version issue. Starting in R2016b, MATLAB does implicit expansion as needed.
With your GLCM matrix being 32 x 32 x 4, then sum(GLCM) is 1 x 32 x 4, and sum() of that is 1 x 1 x 4. You have GLCM ./ that, so you have a 32 x 32 x 4 matrix, ./ a 1 x 1 x 4 matrix.
This is element-wise division between two matrices that are not scalar and are not the same size, because [32 32 4] ~= [1 1 4] .
In R2016a and earlier, element-wise binary operations between matrices that are different size is an error unless one of them is a scalar.
In R2016b and later, MATLAB compares the dimensions that are not equal and checks to see if they are 1 in one of the matrix and not 1 in the other. If that is the case for all of the dimensions that do not match, then MATLAB now replicates the data to match the dimension of the other item. In this case, the 1 x 1 x 4 matrix would be effectively repmat(matrix, [32 32 1]) making it 32 x 32 x 4 which could then be processed through the ./ operator.
R2016a and earlier can do this kind of replication, but you have to know to ask for it, either using repmat() or using bsxfun():
bsxfun(@rdivide, GLCM, sum(sum(GLCM)))

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by