How to remake matrix by using specific cell data??
11 次查看(过去 30 天)
显示 更早的评论
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 个评论
Jan
2016-11-4
编辑:Jan
2016-11-4
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.
回答(1 个)
Jan
2016-11-4
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!