how can i use for loop to solve the below problem

16 ビュー (過去 30 日間)
Christopher Achor
Christopher Achor 2020 年 5 月 22 日
回答済み: Khotso 2025 年 8 月 23 日
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 件のコメント
Christopher Achor
Christopher Achor 2020 年 5 月 22 日
編集済み: Christopher Achor 2020 年 5 月 22 日
Here is the error message as attached.
Saurav Bhagasra
Saurav Bhagasra 2022 年 3 月 4 日
for c = 1:7
s = spectra(:,c)
if speed(c) <=0
loglog(lambda,s,"--")
end
hold on
end

サインインしてコメントする。

採用された回答

Abdolkarim Mohammadi
Abdolkarim Mohammadi 2020 年 5 月 22 日
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.

その他の回答 (2 件)

Damrudhar
Damrudhar 2023 年 1 月 20 日
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 件のコメント
Gemma Lyn
Gemma Lyn 2024 年 1 月 13 日
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
Khotso 2025 年 8 月 23 日

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

カテゴリ

Help Center および File ExchangeInstallation についてさらに検索

タグ

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by