[英]How do I swap array elements mapped to a cell array - matlab
I have a lattice (square array) mapped to an array of cells, how could I make it so that if I swap two array elements I have also swapped the cells mapped to those elements? 我有一个映射到单元格阵列的晶格(正方形阵列),我该怎么做,以便如果我交换两个数组元素,我也已经交换了映射到那些单元格的单元格?
I would really appreciate all suggestions. 我非常感谢所有建议。
Thank you. 谢谢。
The Cells 细胞
l=cell(1,10000);
for i=1:10000
l{i}=[randi(10), randi([0,2])];
end
the array 数组
lattice=1:10000;
map=containers.Map(lattice,l);
lattice=reshape(lattice,100,100)';
now say I want to swap elements 1 and 2 in the array eg lattice([1 2])=lattice([2 1])
现在说我想交换数组中的元素1和2,例如,
lattice([1 2])=lattice([2 1])
I also want this to swap the mapped cells so that l{2} is now l{1} and vice versa. 我还希望它交换映射的单元格,以便l {2}现在是l {1},反之亦然。
Any Ideas? 有任何想法吗?
你知道处理 ?
[l{1}, l{2}] = deal(l{2}, l{1});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.