Single representation of same values in a Matrix
1 次查看(过去 30 天)
显示 更早的评论
Hello.
I have matrix A:
5.00 5.00 3.00 3.00 4.00 4.00
5.00 5.00 3.00 3.00 4.00 4.00
2.00 2.00 1.00 1.00 5.00 5.00
I need to replace all the same valus with a unique value so the matrix I need is:
5 3 4
2 1 5
Any suggestions please
0 个评论
采纳的回答
Stephen23
2019-2-24
>> M = [5,5,3,3,4,4;5,5,3,3,4,4;2,2,1,1,5,5]
M =
5 5 3 3 4 4
5 5 3 3 4 4
2 2 1 1 5 5
>> S = size(M);
>> X = [true(1,S(2));diff(M,1,1)] & [true(S(1),1),diff(M,1,2)];
>> V = sum(X,1);
>> Z = reshape(M(X),V(find(V,1)),[])
Z =
5 3 4
2 1 5
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Resizing and Reshaping Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!