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 Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by