MATLAB Programming Techniques, Extracting Portions of a table
이전 댓글 표시
Hello,
in the course "Programming Techniques" theses lines show how you can extract portions of a table:
t2 = t1(6:15,[1 5 end-1:end])
or
t2 = t1(6:15,["A" "E" "N" "O"])
Why do I need
end-1:end
in the first version?
Lisa
채택된 답변
추가 답변 (1개)
Why do you need it? Well, I don't see the question in the course, and I am not enrolled in the course, so...
But what does that construct do? When you are indexing, the end keyword indicates the last element of a vector or array, in whatever dimension you are looking at. I'll try it out in an example.
V = primes(20)
What does V(end) do?
V(end)
Ah, do you see? It returns the last element. How about this one?
V(end-1:end)
end-1 is the next to last element, so that returns the final two elements. And this one?
V([1, 3, end-1:end])
So the frst element, the third one, and the final two elements.
When it is an array you are working with, TRY IT!
A = magic(7)
A([2 4],[1 end-1:end])
It extracted from rows 2 and 4. And in terms of the columns, it took columns 1 6 and 7. So the 1st column, and the last two columns, since A was a 7x7 array.
카테고리
도움말 센터 및 File Exchange에서 Variables에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!