Matriz dimension issue, a version issue?

1 visualizzazione (ultimi 30 giorni)
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

Risposta accettata

Walter Roberson
Walter Roberson il 12 Apr 2019
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)))

Più risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by