onrammp exercise 14.2 stellar motion part 2, task 6 movaway
Infos
This question is locked. Rouvrir pour modifier ou répondre.
Afficher commentaires plus anciens
For task 6 I don't understand how matlab connects starname to a particular graph.
Also I'm not sure how this piece of code works...
"movaway = starnames(speed < 0) "
how does this line of code use a variable that is in a loop before this line of code?
Sorry in advance if this is an obvious question.
Task 1
[sHa,idx] = min(spectra);
lambdaHa = lambda(idx);
z = lambdaHa/656.28 - 1;
speed = z*299792.458
Tasks 2 - 4
for c = 1:7
s = spectra(:,c);
if speed(c) >= 0
loglog(lambda,s,"--")
else
loglog(lambda,s,"LineWidth",3)
end
hold on
end
hold off
Task 5
legend(starnames)
Task 6
movaway = starnames(speed < 0)
1 commentaire
Nikita
le 12 Fév 2024
Add an if statement to the for loop body. If speed(v) is less than or equal to 0, create a plot of s against lambda using a dashed line (--).
Add the command hold on between the two end keywords so that you only create one plot.
Réponse acceptée
Plus de réponses (1)
Bongani Tavengwa
le 5 Juin 2020
Modifié(e) : DGM
le 22 Fév 2023
Task
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.
for c = 1:7
s = spectra(:,c);
if speed(c) >= 0
loglog(lambda,s,"--")
else
loglog(lambda,s,"LineWidth",3)
end
hold on
end
please help me where do i go wrong
9 commentaires
Steven Lord
le 5 Juin 2020
The instructions state you should create the dashed line loglog plot if speed( c) is less than or equal to 0.
Your code does not contain the less than or equal to operator <=.
Your code does contains the greater than or equal to operator >=.
Bongani Tavengwa
le 5 Juin 2020
so who do i write it then ?? because i m not coming write
Bongani Tavengwa
le 5 Juin 2020
please do advise
Steven Lord
le 5 Juin 2020
Use the less than or equal to operator instead of the greater than or equal to operator.
Bongani Tavengwa
le 7 Juin 2020
Thanks Steven manage to crack it right.
Sergio Andres Cuellar Oliveros
le 23 Nov 2020
Modifié(e) : DGM
le 22 Fév 2023
I get an error, having all the code fine, then he asks me: Is there a graph with seven lines?, please help me
for c = 1:7
s = spectra(:,c);
if speed(c)<= 0
loglog(lambda,s,"--")
else
loglog(lambda,s,"LineWidth",3)
end
hold on
end
hold off
MOHAMMED EL KASMI ALAOUI
le 16 Mai 2022
Modifié(e) : DGM
le 22 Fév 2023
for v = 1:7
s = spectra(:,v);
if speed(v)<= 0
plot(lambda,s,"--")
else
plot(lambda,s,LineWidth=3)
end
hold on
end
hold off
Meifeng
le 30 Juil 2022
for v=1:7
s=spectra(:,v)
if speed(v)<= 0
plot(lambda,s,"--")
end
hold on
end
Narmadha
le 9 Sep 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.
This question is locked.
Catégories
En savoir plus sur Creating and Concatenating Matrices dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!