Write a code to start array only when condition is true

1 visualización (últimos 30 días)
Ashwini  More
Ashwini More el 10 de Abr. de 2020
Comentada: Ashwini More el 10 de Abr. de 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

Respuesta aceptada

Rik
Rik el 10 de Abr. de 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

Más respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by