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

조회 수: 1 (최근 30일)
Hannah 2021년 8월 12일
댓글: Hannah 2021년 8월 12일
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(alpha<0)=0;
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?

댓글을 달려면 로그인하십시오.

### 채택된 답변

Yongjian Feng 2021년 8월 12일
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이전 댓글 -1개 표시이전 댓글 -1개 숨기기
Hannah 2021년 8월 12일
I understand. Thank you!

댓글을 달려면 로그인하십시오.

### 추가 답변 (1개)

John D'Errico 2021년 8월 12일
편집: John D'Errico 2021년 8월 12일
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이전 댓글 -1개 표시이전 댓글 -1개 숨기기
Hannah 2021년 8월 12일
Ok, thank you for the explanation and advice.

댓글을 달려면 로그인하십시오.

### 카테고리

Help CenterFile Exchange에서 Workspace Variables and MAT-Files에 대해 자세히 알아보기

### Community Treasure Hunt

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

Start Hunting!

Translated by