# matrix, where each element is a column vector

2 views (last 30 days)
Alessandro on 4 May 2024
Commented: Image Analyst on 4 May 2024
Excuse me, I need some help. I have an 11*7 matrix. Each element of this matrix consists of a column vector 1001*1. I want to calculate for each column matrix the maximum value. thanks for your help
ETATT=cell(11,7); % initial matrix
Etat=zeros(1001,1); % column vector, contained in each element of the ETATT matrix
I want to find the maximum value of each Etat contained in ETATT
THANKS
Stephen23 on 4 May 2024

John D'Errico on 4 May 2024
Edited: John D'Errico on 4 May 2024
You don't need a cell array at all!
Just use a 3-d array.
A = randn(11,7,1001);
Now to compute the max in each vector, just use max.
Amax = max(A,[],3)
Amax = 11x7
2.8855 3.1273 3.4970 3.4644 3.2119 3.3252 3.3440 3.5491 3.4246 3.0522 3.0026 3.6090 2.8491 3.1710 2.8150 3.1949 2.8692 3.1197 2.9194 3.7617 3.4712 3.7289 3.5455 3.3983 3.9485 3.6122 3.3107 3.0513 2.6401 2.9991 3.3636 4.0458 3.6022 2.7523 2.8631 3.3276 3.4824 3.3375 3.1679 2.9176 3.4002 2.8746 2.8566 2.8198 3.1635 3.1104 2.9772 2.5777 3.4800 3.4694 3.9244 3.4734 2.8729 3.0262 2.9374 3.0426 3.3679 3.0261 3.2774 2.9603 3.1238 2.9358 3.1946 2.9948 3.6696 3.7775 2.9491 3.1029 3.2715 3.2116
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
You can extract any vector from Amax simply enough.
v = Amax(i,j,:);
This will be a 1x1x1001 vector. If you want it to be a true column vector, then just do
v = squeeze(A(i,j,:));
Or, you can store the array as a 1001x11x7 array. Now you can extract the (i,j) vector as
V = rand(1001,11,7);
V(:,1,2)
ans = 1001x1
0.7608 0.4326 0.0963 0.5112 0.7267 0.8622 0.7442 0.4668 0.3008 0.5712
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
Image Analyst on 4 May 2024
John's absolutely right. Don't complicate things by using a cell array if you don't have to, and from what you've said so far, it doesn't appear you have to.

the cyclist on 4 May 2024
ETATT=cell(11,7); % initial matrix
Etat=zeros(1001,1); % column vector, contained in each element of the ETATT matrix
% Fill each cell with a random column vector
for ii=1:11
for jj=1:7
ETATT{ii,jj} = rand(1001,1);
end
end
% Find the max of each vector
maxEtat = cellfun(@max,ETATT);