how can i use for loop to solve the below problem

14 visualizaciones (últimos 30 días)
Christopher Achor
Christopher Achor el 22 de Mayo de 2020
Respondida: Khotso el 23 de Ag. de 2025
Add an if statement to the for loop body. If speed(c) is less than or equal to 0, create a loglog plot of s against lambda using a dashed line (--).
After the if statement, add the command hold on so that only one plot is created.
the below didnt work for me:
if speed(c) <= 0
loglog(lambda,s,"--")
end
hold on
end
  3 comentarios
Christopher Achor
Christopher Achor el 22 de Mayo de 2020
Editada: Christopher Achor el 22 de Mayo de 2020
Here is the error message as attached.
Saurav Bhagasra
Saurav Bhagasra el 4 de Mzo. de 2022
for c = 1:7
s = spectra(:,c)
if speed(c) <=0
loglog(lambda,s,"--")
end
hold on
end

Iniciar sesión para comentar.

Respuesta aceptada

Abdolkarim Mohammadi
Abdolkarim Mohammadi el 22 de Mayo de 2020
You have used an extra end. Delete the end in the last line. I think you must use hold on before your for loop and place the if inside the for loop.

Más respuestas (2)

Damrudhar
Damrudhar el 20 de En. de 2023
Add an else statement. If speed(v) is greater than 0, create a plot of s against lambda using a line width of 3.
After the for loop, enter hold off.
  1 comentario
Gemma Lyn
Gemma Lyn el 13 de En. de 2024
for v = 1:7
s = spectra(:,v)
if speed(v) <=0
plot(lambda,s,"--")
else speed(v) >0
plot(lambda,s,LineWidth=3)
end
hold on
end
hold off

Iniciar sesión para comentar.


Khotso
Khotso el 23 de Ag. de 2025

for v = 1:7 s = spectra(:,v) if speed(v) <=0 plot(lambda,s,"--") else speed(v) >0 plot(lambda,s,LineWidth=3) end hold on end hold off

Categorías

Más información sobre Installation en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by