Find index in each column of a matrix using for

1 回表示 (過去 30 日間)
Cary
Cary 2015 年 6 月 28 日
コメント済み: Star Strider 2015 年 6 月 28 日
Good evening,
I am attempting to find the index of the last non-NaN for each column in a matrix. I can't really get it to work correctly; instead of giving me a column vector of indices, it sums the indices together in every cell. Here is my code:
xDate=zeros(1,size(forward,2)); % preallocate a vector
xDate=xDate'; % transpose to a column
for i = 1:size(forward,2)
xDate(i) = find(~isnan(forward),1,'last')
end
I'm sure it is an easy fix; but I've been racking my brain on it for hours now with no solution.
Thanks to all who are generous enough to help.

採用された回答

Star Strider
Star Strider 2015 年 6 月 28 日
I don’t have your ‘forward’ matrix so this is just a guess.
See if indexing ‘forward’ as well works:
xDate(i) = find(~isnan(forward(:,i)),1,'last')
  2 件のコメント
Cary
Cary 2015 年 6 月 28 日
Beautiful! Thank you very much :)
Star Strider
Star Strider 2015 年 6 月 28 日
As always, my pleasure!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by