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 件)
John D'Errico
2024 年 6 月 18 日
編集済み: John D'Errico
2024 年 6 月 18 日
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!