how can i use for loop to solve the below problem
Show older comments
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 Comments
Geoff Hayes
on 22 May 2020
Chirstopher - please clarify what you mean by the below didn't work for me. The code seems correct (unless you should be plotting loglog(s,lambda,'--')?) so please post any error messages or discuss why it isn't doing what you expect.
Christopher Achor
on 22 May 2020
Edited: Christopher Achor
on 22 May 2020
Saurav Bhagasra
on 4 Mar 2022
for c = 1:7
s = spectra(:,c)
if speed(c) <=0
loglog(lambda,s,"--")
end
hold on
end
Accepted Answer
More Answers (2)
Damrudhar
on 20 Jan 2023
0 votes
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 Comment
Gemma Lyn
on 13 Jan 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
Khotso
on 23 Aug 2025
0 votes
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
Categories
Find more on Installation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!