poster
2019-12-10, 20:30
我在MATLAB中 (http://en.wikipedia.org/wiki/MATLAB)有一个45x2的单元格,第一列是任意大小的双精度矩阵。
其中一些矩阵是重复的,而其他则不重复。我试图仅去除唯一的矩阵(但记录重复的次数),并保持第二列不变。
我已经尝试了许多方法(制表,历史等),但是由于细胞结构(我认为),它们都失败了。如果不逐一遍历每个人,该如何去做呢?
回答:
如果将矩阵转换为字符串,则可以在它们上运行唯一的:
%# create a sample cell array mc = {magic(3);magic(4);magic(4);magic(5);magic(3);magic(4)} %# convert to strings mcs = cellfun(@(x)(mat2str(x)),mc,'uniformoutput',false); %# run unique [uniqueCells,idxOfUnique,idxYouWant] = unique(mcs);
更多&回答... (https://stackoverflow.com/questions/2392256)
其中一些矩阵是重复的,而其他则不重复。我试图仅去除唯一的矩阵(但记录重复的次数),并保持第二列不变。
我已经尝试了许多方法(制表,历史等),但是由于细胞结构(我认为),它们都失败了。如果不逐一遍历每个人,该如何去做呢?
回答:
如果将矩阵转换为字符串,则可以在它们上运行唯一的:
%# create a sample cell array mc = {magic(3);magic(4);magic(4);magic(5);magic(3);magic(4)} %# convert to strings mcs = cellfun(@(x)(mat2str(x)),mc,'uniformoutput',false); %# run unique [uniqueCells,idxOfUnique,idxYouWant] = unique(mcs);
更多&回答... (https://stackoverflow.com/questions/2392256)