필터 지우기
필터 지우기

Write a code to start array only when condition is true

조회 수: 1 (최근 30일)
Ashwini  More
Ashwini More 2020년 4월 10일
댓글: Ashwini More 2020년 4월 10일
The condition which I am writing a code is array has to be start to import elements when condition is true. briefly, I can say that original array contains approximately 100 elements which contains numbers between 50 to 70, for eg. [52 51 52 53 55 56 58 60 52 54 .......]. Now I want to design a new array which should contains element of previous array but it should start from number greater than 55 and exclude numbres less than 55. again there is condition that only intial numbres less than 55 should exclude and when array start to take element, it should take all numbers.
A = [52; 51; 52; 53; 55; 56; 58; 60; 52; 54 ];
for i = drange(1:length(A))
while A < 55
A = [];
if A > 55
continue
end
end
end

채택된 답변

Rik
Rik 2020년 4월 10일
Your code is very confusing, so I am going to ignore it. Just one tip: you need to make sure your condition is a scalar, and you need to make sure you are using your loop index.
As for your goal: if you want to remove all values before the first value greater than 55 you can use this code:
ind=find(A>55,1);
if ~isempty(ind)
A(1:(ind-1))=[];
end

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by