Combination of "for loop" and "if statement"
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I have an assignment that requires me to use both 'for loop' and 'if statement'. However I have zero clue how to start. The question is something like:
machine runs at below 3 Knots means not working
machine runs at 3 to 5 Knots is average
machine runs at above 4 Knots is good
In my excel sheet I have one column for the time and another column matching it by side are the Knot values. I have a total of 400 plus data in my excel sheet.
How do i put this into codes when I was to find how long the machine spend running in total average speeed and how long running in good speed only?
Idk how to link the two coloumns tgt.
if ???
if (y<3)
display ('not working')
elseif(3<y<5)
display ('average')
else(y>5)
display('good')
end
end
4 comentarios
Stephen23
el 17 de Jun. de 2021
Editada: Stephen23
el 17 de Jun. de 2021
Original question by Cynthia Lee on 16th of March 2021, retrieved from Bing Cache:
I have an assignment that requires me to use both 'for loop' and 'if statement'. However I have zero clue how to start. The question is something like:
machine runs at below 3 Knots means not working
machine runs at 3 to 5 Knots is average
machine runs at above 4 Knots is good
In my excel sheet I have one column for the time and another column matching it by side are the Knot values. I have a total of 400 plus data in my excel sheet.
How do i put this into codes when I was to find how long the machine spend running in total average speeed and how long running in good speed only?
Idk how to link the two coloumns tgt.
if ???
if (y<3)
display ('not working')
elseif(3<y<5)
display ('average')
else(y>5)
display('good')
end
end
Respuestas (1)
Walter Roberson
el 13 de Mzo. de 2021
rng(655321)
times = datetime('now') - minutes(sort(randi(600,10,1),'descend'))
knots = rand(10,1)*8
G = discretize(knots, [0 3 4 8], 'categorical', {'not working', 'average', 'good'})
idx = find(G(1:end-1)=="good")
sum(times(idx+1)-times(idx))
5 comentarios
Walter Roberson
el 13 de Mzo. de 2021
times = readmatrix('NameOfTimeFile.xlsx');
knots = readmatrix('NameOfKnotsFile.xlsx');
G = discretize(knots, [0 3 5 15], 'categorical', {'not working', 'average', 'good'});
average_times = nnz(G=="average");
good_times = nnz(G=="good");
Ver también
Categorías
Más información sobre Timing and presenting 2D and 3D stimuli 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!