How can I place all the values less than 1 into a new array

1 回表示 (過去 30 日間)
ubaid haroon
ubaid haroon 2016 年 8 月 2 日
コメント済み: ubaid haroon 2016 年 8 月 3 日
Lets say I have an array x = [ 1 2 3 4 5 6 0 1 0 4 0 8 0 8 6 0], from which I want to read only the zeros and place them in a new array. so far I have this
for i = 1:size(x)
for m = 1:size(x)
if x(i) < 1
newArray = [x(m) > 1]
end
end
end
Not sure how to implement this. any help would be appreciated

採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2016 年 8 月 2 日
編集済み: Azzi Abdelmalek 2016 年 8 月 2 日
x = [ 1 2 3 4 5 6 0 1 0 4 0 8 0 8 6 0]
out=x(x<1)
you can calculate
y=setdiff(x,out)
  1 件のコメント
ubaid haroon
ubaid haroon 2016 年 8 月 3 日
Thank you Azzi, I did not know it was as simple as that. That was very helpful!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by