How do I convert a 3x153 double to a 1x51 matrix?
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
How do I convert a 3x153 double to a 1x51 cell in matricies?
And how do i multiply the answer by another matrix?
0 comentarios
Respuestas (1)
Voss
el 15 de En. de 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 comentarios
Ver también
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!