How to get last numerical value from column A only?

85 ビュー (過去 30 日間)
isamh
isamh 2020 年 3 月 13 日
回答済み: Steven Lord 2020 年 3 月 13 日
I have a CSV, I want to get the first and last value from column A.
I found the first value, which is: First = P(1);
i cant seem to get the last value, I tried: Last = P(end);
I get the last value from Column E instead of A

採用された回答

Fangjun Jiang
Fangjun Jiang 2020 年 3 月 13 日
P(1,end) would be it.
  3 件のコメント
isamh
isamh 2020 年 3 月 13 日
nevermind got it, it's: P(end,1);
Fangjun Jiang
Fangjun Jiang 2020 年 3 月 13 日
:) You got it right

サインインしてコメントする。

その他の回答 (1 件)

Steven Lord
Steven Lord 2020 年 3 月 13 日
When you index into an array with just one index, you're using a technique called linear indexing. This basically treats your array like it was one long vector, as described in the "Indexing with a Single Index" section on this documentation page. You want to perform subscripted indexing, as Fangjun Jiang suggested and as the "Indexing with Element Positions" section on that documentation page states. That section mentions the end keyword will will be very useful in keeping your code generalized. This avoids hard-coding in the size of a particular array, letting your code automatically handle different sized inputs without needing modification.

カテゴリ

Help Center および File ExchangeMultidimensional Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by