Removing zero values from an array

512 次查看(过去 30 天)
I have an n x 1 array containing values. For exmaple A =
1
0
0
2
0
3
I was wondering if it was possible to create another array except without the zero values. For example
B =
1
2
3
  1 个评论
Stephen23
Stephen23 2022-3-21
A = [1;0;0;2;0;3]
A = 6×1
1 0 0 2 0 3
B = nonzeros(A) % Introduced before R2006a
B = 3×1
1 2 3

请先登录,再进行评论。

采纳的回答

Star Strider
Star Strider 2015-5-14
Using logical indexing, you can calculate ‘B’ in one line:
B = A(A~=0)
  6 个评论
Star Strider
Star Strider 2015-5-14
Thank you Walter.
I was away for a few minutes with another Answer.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 MATLAB 的更多信息

标签

产品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by