How do I convert a 3x153 double to a 1x51 matrix?
3 views (last 30 days)
Show older comments
How do I convert a 3x153 double to a 1x51 cell in matricies?
And how do i multiply the answer by another matrix?
0 Comments
Answers (1)
Voss
on 15 Jan 2022
% Create a 3-by-153 matrix with random data:
A = rand(3,153)
% Convert the 3-by-153 matrix to a 1-by-51 cell array, with each element being a 3-by-3 matrix:
C = mat2cell(A,3,3*ones(1,51))
% Verify the size of the cell array:
size(C)
% Verify that the first element of C is the first 3 columns of A:
C{1}
isequal(C{1},A(:,1:3))
% Now multiply each element of C by some other matrix B of unspecified size (using 3-by-3 here):
B = magic(3)
% matrix mulitplication:
D = cellfun(@(x)x*B,C,'UniformOutput',false)
D{1}
% or element-wise multiplication:
D = cellfun(@(x)x.*B,C,'UniformOutput',false)
D{1}
0 Comments
See Also
Categories
Find more on Creating and Concatenating Matrices 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!