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

조회 수: 2 (최근 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 CenterFile Exchange에서 Logical에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by