What does a=[b(90:end) b(1:89)] represent ?

2 Ansichten (letzte 30 Tage)
Hannah
Hannah am 12 Aug. 2021
Kommentiert: Hannah am 12 Aug. 2021
See code section below:
temp1= hor(tilt(t), h, d1, d2,col5, a_z); %call function
temp2=[temp1(90:end) temp1(1:89)];
hor_Mxt(t,r,col5).alphaS = temp1;
hor_Mxt(t,r,col5).alphaE = temp2;
function alpha=hor(~, h, d1, d2, col5, a_z)
alpha=rad2deg(atan(cosd(a_z)*h/d1));
alpha(alpha<0)=0;
az_frame=rad2deg(atan(col5/d2));
alpha(a_z>az_frame)=0;
end
I do not understand what is the relation between temp1 and temp2. What is temp1 storning and what is temp2 storing?

Akzeptierte Antwort

Yongjian Feng
Yongjian Feng am 12 Aug. 2021
temp1 stores the return from calling hor. It is an array of more than 90 elements.
temp2 reverts the order of some element. This code can show you how temp2 is related to temp1:
temp1 = 1:100; % if temp1 is 1, 2, 3, .... , 99, 100
temp2=[temp1(90:end) temp1(1:89)] % check what temp2 looks like

Weitere Antworten (1)

John D'Errico
John D'Errico am 12 Aug. 2021
Bearbeitet: John D'Errico am 12 Aug. 2021
You very clearly need to spend some time with a MATLAB manual or tutorial. You are asking a basic question, that would be covered at the very beginning of any such document.
What does temp1(90) do? Answer: it extracts element 90 of the vector.
What would temp1(91) do? Answer: it extracts element 91 of the vector. Etc.
What would temp1(90:93) do? Answer: It extracts elements [90 91 92 93] from the vector.
What would temp1(90:end) do? Answer: It extracts all the elements from #90 to the very end of the vector.
For example...
temp1 = primes(20)
temp1 = 1×8
2 3 5 7 11 13 17 19
temp1(5:end)
ans = 1×4
11 13 17 19
So it extracted the 5th element, up to the very last element.
Similarlly,
temp1(1:4)
ans = 1×4
2 3 5 7
So the first 4 elements of the vector.
Now, how can we combine parts of vectors into a new vector? We use the square brackets, thus [].
temp2 = [temp1(5:end) ,temp1(1:4)]
temp2 = 1×8
11 13 17 19 2 3 5 7
Now go back and look at your question. How did this rearrange the elements of our example vector? What would it do in your problem?
And then go back and read the help documents for MATLAB. I suggest the MATLAB Onramp tutorials. But you can also find guided tutorials on YouTube.
  1 Kommentar
Hannah
Hannah am 12 Aug. 2021
Ok, thank you for the explanation and advice.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Workspace Variables and MAT-Files finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by