Write a code to start array only when condition is true

1 次查看(过去 30 天)
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