need help with this task in matlab onramp final project

12 ビュー (過去 30 日間)
richard
richard 2023 年 4 月 5 日
コメント済み: Cris LaPierre 2025 年 8 月 6 日
[sHa,idx] = min(spectra);
lambdaHa=lambda(idx);
z=lambdaHa 1656.28-1;
speed=2*299792.958
for v=1:7
s = spectra(:'v)
end
This is the part that I keep getting stuck on:
Add it statement to the for loop body if speed (v) is less than or equal to 0
Create a plot of s against lambda using dashed line (--)
Add hold on command between two end keywords.
* So this is what I put down*
if speed(v) <= 0
plot(lambda, s, "--")
end
hold on
end
What did I do wrong or miss?
  2 件のコメント
Cris LaPierre
Cris LaPierre 2023 年 4 月 5 日
編集済み: Cris LaPierre 2023 年 4 月 5 日
When you Submit, what are the results of the assessment tests?
  • Did you create a plot with four lines?
  • Did you plot lambda on the x-axis?
  • Did you plot s on the y-axis?
  • Did you use a dashed linestyle?
  • Did you set hold to on?
  • Did you include the code <= in the script?
richard
richard 2023 年 4 月 5 日
The entire code above to where I stated the if staement
results showed:
it showed a red x on the following
did you create a plot with four lines? x
did you plot lambda on x-axis? x
did you plot s on y-axis? x
did you use the dashed linestyle? x
did you set hold on?
did you include the code <=0? i got a gree check here

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

回答 (2 件)

Image Analyst
Image Analyst 2023 年 4 月 5 日
I think you want dashed if it's below 0 and solid line if it's above 0, so something like
negativeIndexes = speed(v) <= 0; % A logical index vector.
% Plot negative values with dashed lines
plot(lambda(negativeIndexes), s(negativeIndexes), "--")
% Plot positive values with a solid line.
hold on;
plot(lambda(~negativeIndexes), s(~negativeIndexes), "-");
  1 件のコメント
Walter Roberson
Walter Roberson 2023 年 4 月 5 日
Not exactly, this would draw a line between non-adjacent parts.

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


Cris LaPierre
Cris LaPierre 2023 年 4 月 5 日
編集済み: Cris LaPierre 2023 年 4 月 5 日
You appear to have replaced the for loop rather than adding the if statement to it.
If I take the code you have shared and add it correctly to the for loop, as shown in the Solution, it passes all assessment tests.
  6 件のコメント
Cris LaPierre
Cris LaPierre 2025 年 8 月 4 日
編集済み: Cris LaPierre 2025 年 8 月 4 日
What are you seeing? If you code is the same as what is shown in 'See Solution', yet you are getting marked Incorrect, that sounds like what is reported here. Please follow the suggestions given in that post.
Cris LaPierre
Cris LaPierre 2025 年 8 月 6 日
Here is another post that sounds like what you are seeing. Please try the solution offered there (clear cache and cookies)

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

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by