How to build a loop through every column and row of a cell

9 visualizaciones (últimos 30 días)
Julia Gorman
Julia Gorman el 25 de Jul. de 2022
Respondida: Voss el 25 de Jul. de 2022
I have a 32 x 3 MATLAB cell and I want to loop through every one of the 96 cells to find the single largeset value contained in all of them? How might I go about doing that.

Respuesta aceptada

Voss
Voss el 25 de Jul. de 2022
% first, I create a 32x3 cell array of random 10x10 matrices
C = arrayfun(@(x)randn(10),zeros(32,3),'uni',false)
C = 32×3 cell array
{10×10 double} {10×10 double} {10×10 double} {10×10 double} {10×10 double} {10×10 double} {10×10 double} {10×10 double} {10×10 double} {10×10 double} {10×10 double} {10×10 double} {10×10 double} {10×10 double} {10×10 double} {10×10 double} {10×10 double} {10×10 double} {10×10 double} {10×10 double} {10×10 double} {10×10 double} {10×10 double} {10×10 double} {10×10 double} {10×10 double} {10×10 double} {10×10 double} {10×10 double} {10×10 double} {10×10 double} {10×10 double} {10×10 double} {10×10 double} {10×10 double} {10×10 double} {10×10 double} {10×10 double} {10×10 double} {10×10 double} {10×10 double} {10×10 double} {10×10 double} {10×10 double} {10×10 double} {10×10 double} {10×10 double} {10×10 double}
% now loop through all the cells and store
% the largest value in each cell
C_max = zeros(size(C));
for ii = 1:numel(C)
C_max(ii) = max(C{ii}(:));
end
C_max
C_max = 32×3
2.0129 2.2185 2.5962 1.6750 2.0335 2.5236 2.5415 2.8507 2.3550 3.0317 3.2665 2.4372 3.1738 2.4802 2.2340 2.2609 2.5011 3.6321 2.3977 1.9500 2.2795 2.4205 2.4711 2.3772 2.7915 1.6535 2.1038 2.8421 2.0512 2.6285
% finally, the single largest value
C_max = max(C_max(:))
C_max = 4.0026

Más respuestas (0)

Categorías

Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by