How to find the first value coordinate(the minimum non-zero x coordinate) in each row?

1 回表示 (過去 30 日間)
How to find the first value coordinate(the minimum non-zero x coordinate) in each row?
and what if each row value coordinate gap were to big how to smooth it ,connect each row to a smooth line? thanks
fclose all; close all; clear all; clf; clc;
A=[0,1,1;0,1,0;1,0,0];
[row,column]=find(A==min(min(1)));

採用された回答

Ameer Hamza
Ameer Hamza 2020 年 5 月 19 日
編集済み: Ameer Hamza 2020 年 5 月 19 日
If matrix just contains 0 and 1
[~,idx] = max(A, [], 2)
Result
>> idx
idx =
2
2
1
For a general case
[~,idx] = max(A~=0, [], 2)
  3 件のコメント
Ameer Hamza
Ameer Hamza 2020 年 5 月 19 日
I am glad to be of help.
Willis
Willis 2022 年 8 月 28 日
Hello?
What if the matrix (size of 207 x 7) contain not just 0 or 1 but other values?
I need to find the minimum values (not the indices) of each row except zero.
Could you help me for this?
Thank you!

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

その他の回答 (1 件)

darova
darova 2020 年 5 月 19 日
Try this
a = zeros(size(A,1),1);
for i = 1:length(a)
a(i) = find(A(i,:),1,'first')
end

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by