# Write a code to start array only when condition is true

1 view (last 30 days)
Ashwini More on 10 Apr 2020
Commented: Ashwini More on 10 Apr 2020
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
Walter Roberson on 10 Apr 2020
A(~cumprod(A<55))

Rik on 10 Apr 2020
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
Ashwini More on 10 Apr 2020
thank u so much!!