I have a set 120 values and i want to take 1st 4 values and divide with a ref. no.and check for a condition if it is not satisfied i want to take next 4 values and repeat like this by using for loop.can u plz help.

 Akzeptierte Antwort

Bhaskar R
Bhaskar R am 30 Jan. 2020

1 Stimme

y = randi(100, 1, 120); % assumed data of length 120
for ii = 1:4:length(y)
values_4 = y(ii:ii+3); % fou
if mean(values_4) ~= 10 % assumed condition here
% your operation
else
break; % operation breaks here
end
end

3 Kommentare

sir thanku for your answer. There is a problem when running this program .
for i=0:4:120
for j=1:i
end
end
while running this we get 1...4,1...8,....etc.
i want to get 1....4 then 5....8 like this.How to solve this
for i=1:4:120
for j=i:i+3
end
end
nayana k
nayana k am 31 Jan. 2020
Thanku sir .

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Gefragt:

am 30 Jan. 2020

Kommentiert:

am 31 Jan. 2020

Community Treasure Hunt

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

Start Hunting!

Translated by