How to remake matrix by using specific cell data??
11 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I have a 1X4 cell and 4X12 matrix
cell(1,1) = [3,4,5,7,9]
cell(1,2)= [3,4,5,6,7,8,9,10,11,12]
cell(1,3) = [1,4,6,7,8,9,11,12]
cell(1,4) = [4,5,8,9,10,11,12]
Matrix = [1 2 3 4 5 6 7 8 9 10 11 12;
4 5 6 7 8 9 10 11 12 1 2 3;
7 8 9 10 11 12 1 2 3 4 5 6;
12 10 11 9 8 7 6 5 4 3 2 1];
I want to make another matrix by using cell data like...
New_Matrix = [0 0 3 4 5 0 7 0 9 0 0 0;
0 0 6 7 8 9 10 11 12 1 2 3;
7 0 0 10 0 12 1 2 3 0 5 6;
0 0 0 0 8 7 0 0 4 3 2 1];
I tried many time but error like subindex is not defined for cell and dimension is not matched... pleases help me.
1 comentario
Jan
el 4 de Nov. de 2016
Editada: Jan
el 4 de Nov. de 2016
Please explain the magic relation between the inputs and the outputs. We could guess the wanted procedure, but it is more efficient, if you reveal this important detail. If you post your code, suggesting an improvement would be much easier.
Please post your inputs such, that we can copy&paste it in Matlab directly. Otherwise trying to create a solution requires more typing for all voluntary helpers. Thanks.
Respuestas (1)
Jan
el 4 de Nov. de 2016
Perhaps - a bold guess:
C = {[3,4,5,7,9], ...
[3,4,5,6,7,8,9,10,11,12], ...
[1,4,6,7,8,9,11,12], ...
[4,5,8,9,10,11,12]};
M = [1 2 3 4 5 6 7 8 9 10 11 12; ...
4 5 6 7 8 9 10 11 12 1 2 3; ...
7 8 9 10 11 12 1 2 3 4 5 6; ...
12 10 11 9 8 7 6 5 4 3 2 1];
NewM = zeros(size(M));
for k = 1:size(M, 1)
NewM(k, C{k}) = M(k, C{k});
end
0 comentarios
Ver también
Categorías
Más información sobre Logical 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!