normalization of cell arrays

5 views (last 30 days)
yasmine
yasmine on 6 Jan 2012
Commented: Asma on 4 Nov 2024
Hi
i want to normalize the values in a cell array called G
G is partitioned into 6 blocks (cell arrays) so i want to normalize each block separately (G{i,j}), each block is of size 128X128
Gmin = min((G(:)));
Gnorm = (G - Gmin) ./ (max(G1{:,:}) - Gmin);
i tried this:
Gmin(i,j)=min(G{i,j});
but i got this error:
??? Undefined function or method 'min' for input arguments of type 'cell'.
Error in ==> DOC at 124
Gmin(i,j)=min(G{i,j});
any suggestions please ???

Accepted Answer

Walter Roberson
Walter Roberson on 6 Jan 2012
Gmin = cellfun(@(M) min(M(:)), G, 'Uniform', 0);
Gmax = cellfun(@(M) max(M(:)), G, 'Uniform', 0);
Gnorm = cellfun(@(M,minM,maxM) (M-minM) ./ (maxM-minM)), G, Gmin, Gmax, 'Uniform', 0);
This relies on two uncommon usages:
  • deliberately returning a cell array when the results would fit in a vector
  • passing multiple cell arrays in to cellfun(), knowing that the corresponding elements will be extracted from each and passed to the function handle
There are other ways of coding this, such as using arrayfun()
  2 Comments
yasmine
yasmine on 6 Jan 2012
unfortunately,i had this error:
??? Undefined function or method 'min' for input arguments of type 'cell'.
Error in ==> @(M)min(M(:))
Error in ==> DOC at 129
Gmin = cellfun(@(M) min(M(:)), G, 'Uniform', 0);
Asma
Asma on 4 Nov 2024
the error occurs probably due to the presence of non-numeric or absent values, try checking for isnumeric before proceeding
% Check which cells are numeric isNumericCell = cellfun(@isnumeric, G);

Sign in to comment.

More Answers (0)

Categories

Find more on Encryption / Cryptography in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!