How can I extract a specific row of data from each column of a matrix

1 回表示 (過去 30 日間)
John Harry
John Harry 2016 年 9 月 30 日
回答済み: James Tursa 2016 年 9 月 30 日
Hello, Matlabbers.
I have 286x8 matrix (X) where each column of data has a different number of numerical data points followed by NaNs to create a length of 268 for each column. I have identified the last row of numerical data in each column using the command Y = sum(isfinite(X)) which returns a 1x8 row of data identifying the final data point of non-NaN values. What I need to do now is extract the data from each column of X corresponding to each value in Y. Nothing I have tried has worked. Does anyone have any suggestions for how to extract these values?
Thanks, John

採用された回答

John Harry
John Harry 2016 年 9 月 30 日
I did some extra digging, and was able to get the data I need using a basic for loop (Not sure why a loop with this structure did not cross my mind earlier!). The loop that did the trick was:
for i = 1:length(Y)
X_Y(i) = X(Y(i),i)
end

その他の回答 (2 件)

Eamon
Eamon 2016 年 9 月 30 日
X(Y(1))
should work to get that data point for the first column of X,
X(Y(2))
for the second column of X, etc.

James Tursa
James Tursa 2016 年 9 月 30 日
X_Y = X(Y + (0:numel(Y)-1)*size(X,1));

カテゴリ

Help Center および File ExchangeGeographic Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by