Effacer les filtres
Effacer les filtres

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

1 vue (au cours des 30 derniers jours)
Hannah le 12 Août 2021
Commenté : Hannah le 12 Août 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)
I do not understand what is the relation between temp1 and temp2. What is temp1 storning and what is temp2 storing?

Réponse acceptée

Yongjian Feng
Yongjian Feng le 12 Août 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
  1 commentaire
Hannah le 12 Août 2021
I understand. Thank you!

Connectez-vous pour commenter.

Plus de réponses (1)

John D'Errico
John D'Errico le 12 Août 2021
Modifié(e) : John D'Errico le 12 Août 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
ans = 1×4
11 13 17 19
So it extracted the 5th element, up to the very last element.
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 commentaire
Hannah le 12 Août 2021
Ok, thank you for the explanation and advice.

Connectez-vous pour commenter.


En savoir plus sur Workspace Variables and MAT-Files dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by