onrammp exercise 14.2 stellar motion part 2, task 6 movaway

367 ビュー (過去 30 日間)
Darnell Gawdin
Darnell Gawdin 2020 年 1 月 3 日
回答済み: tania 2024 年 3 月 12 日 21:42
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 件のコメント
Nikita
Nikita 2024 年 2 月 12 日
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.

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

採用された回答

KALYAN ACHARJYA
KALYAN ACHARJYA 2020 年 1 月 3 日
編集済み: KALYAN ACHARJYA 2020 年 1 月 3 日
See the example, lets suppose starnames is variable having all types of numbers
starnames=[-2 3 45 7 2 0 -4 5 7 7 6 9];
speed=[2 3 -4 5 6 7 8 0 5 2 -30] ; % Just random example
## speed<0 is an conditional assignment, its return a logical array (with 0 & 1), when condition true, its 1, otherwise 0
>> speed < 0
ans =
1×11 logical array
0 0 1 0 0 0 0 0 0 0 1
## starnames(speed < 0) return an array, where the 1 presence in the above logical array
>> movaway = starnames(speed < 0)
movaway =
45 6
This is just an example to understand the issue (This approach is good way for efficient code, conditional & array indexing)
  1 件のコメント
Darnell Gawdin
Darnell Gawdin 2020 年 1 月 3 日
Thank you for your time and expertise to answer this question. I see how it works now.

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

その他の回答 (2 件)

Bongani Tavengwa
Bongani Tavengwa 2020 年 6 月 5 日
編集済み: DGM 2023 年 2 月 22 日
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 件のコメント
Meifeng
Meifeng 2022 年 7 月 30 日
for v=1:7
s=spectra(:,v)
if speed(v)<= 0
plot(lambda,s,"--")
end
hold on
end
Narmadha
Narmadha 2023 年 9 月 9 日
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.

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


tania
tania 2024 年 3 月 12 日 21:42
Habiendo creado un script en tiempo real para encontrar el desplazamiento al rojo, puede modificar fácilmente este script para repetir el cálculo con cualquier estrella de la matriz spectra.
ACTIVIDAD
Modifique la sección Tasks 2 & 7 del script para que realice el cálculo del desplazamiento al rojo con la segunda estrella de spectra en lugar de la sexta.
s = spectra(:,2)
[sHa,idx] = min(s)
lambdaHa = lambda(idx)
z = lambdaHa/656,28 - 1
velocidad = z*299792.458
Test Results:
¡Incorrecto!
¿Es s la segunda columna de spectra?
¿Tiene lambdaHa el valor correcto?
¿Tiene speed el valor correcto?
cual es el error ???

カテゴリ

Help Center および File Exchange2-D and 3-D Plots についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by