matrix, where each element is a column vector
3 次查看(过去 30 天)
显示 更早的评论
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
1 个评论
回答(2 个)
John D'Errico
2024-5-4
编辑:John D'Errico
2024-5-4
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)
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)
1 个评论
Image Analyst
2024-5-4
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
2024-5-4
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);
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!