What does a=[b(90:end) b(1:89)] represent ?
2 views (last 30 days)
See code section below:
temp1= hor(tilt(t), h, d1, d2,col5, a_z); %call function
hor_Mxt(t,r,col5).alphaS = temp1;
hor_Mxt(t,r,col5).alphaE = temp2;
function alpha=hor(~, h, d1, d2, col5, a_z)
I do not understand what is the relation between temp1 and temp2. What is temp1 storning and what is temp2 storing?
Yongjian Feng on 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
More Answers (1)
John D'Errico on 12 Aug 2021
Edited: John D'Errico on 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.
temp1 = primes(20)
So it extracted the 5th element, up to the very last element.
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)]
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.