Finding first rightmost non-zero column of a matrix?

9 ビュー (過去 30 日間)
Teresita Ramirez Aguilar
Teresita Ramirez Aguilar 2019 年 8 月 15 日
How can I tell MATLAB to find the index of the RIGHTmost non-zero column of said matrix?
I found a similar question and answer for the leftmost column and it worked great! However, I am having trouble finding the rightmost column.
I need the leftmost column.
PLS&THANKYOU!
  1 件のコメント
Teresita Ramirez Aguilar
Teresita Ramirez Aguilar 2019 年 8 月 15 日
I tried looking here https://www.mathworks.com/help/matlab/ref/find.html but nothing I tried is working, new to Matlab..

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

採用された回答

dpb
dpb 2019 年 8 月 15 日
編集済み: dpb 2019 年 8 月 15 日
Same solution as the other except search from the other end...
find(any(A),1,'last')
I think Azzi's solution there doesn't find the column positionally but will find the column with the largest number of nonzero elements in it. So
[2 1
0 1
0 1]
with his would return 2, not 1 because three rows of second column return T but only one of column 1 will. But both have nonzero elements.
any() does the logical test by column for there being one or more nonzero elements so doesn't matter how many there are as long is one it'll show up. Then the find() locates either first or last depending on which direction you ask for with the optional argument.
  5 件のコメント
dpb
dpb 2019 年 8 月 16 日
I just noticed the "image" tag so that's a possibility...something inconsistent with the assumption matrix meant 2D array :)
Teresita Ramirez Aguilar
Teresita Ramirez Aguilar 2019 年 8 月 16 日
Walter Roberson's answer worked! But I really appreciate everyones help very much !!! :D I apologize for any confusion on my part, I am very new to MATLAB.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by