MatLab; How to arrange strings in ascending order, but ignore null values?

If I have a matrix like:

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] 

and I use the sort (A, 2) command, it will be sorted next to the columns, but at the same time shift the zeros forward. I would like to leave 0 to the end for computational purposes later in the code.

I was looking for a team that does this because I feel that it is. I also tried sorting, flipping and wrapping to get what I want, but Im at a dead end.

+1
source share
1 answer

You can replace 0 with Inf , then sort, and after sorting, replace Inf with 0 again.

+6
source

Source: https://habr.com/ru/post/946345/


All Articles