本文介绍了MatLab,如何按升序组织行,但忽略零值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有这样的矩阵:

A=[ 8 3 67 8 2 0 0 0 0 0; 8 76 9 233 1 89 34 0 0 0; 98 23 87 9 3 24 64 45 1 0]

,我使用命令sort(A,2)它将在列旁边排序,但同时将零向前推.我想在代码中稍后将0保留到最后以用于计算目的.

and I use the command sort(A,2) it will sort alongside the columns but at the same time push the zeros forward. I would like to keep the 0's to the end for computing purposes later on in the code.

我一直在寻找可以执行此操作的命令,因为我觉得有一个.我通常也一直在尝试排序,翻转和转置以获得我想要的东西,但是Im陷入了僵局.

I I have been looking for a command that does this, as I feel there is one.I have also generally been trying to sort, flip, and transpose to get what I want but Im at an impasse.

推荐答案

您可以将0替换为Inf,然后进行排序,并在排序后再次将Inf替换为0.

You can replace the 0 by Inf, then sort and after the sort replace the Inf by 0 once again.

这篇关于MatLab,如何按升序组织行,但忽略零值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 02:36
查看更多