MATLAB Answers

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

5 views (last 30 days)
HUANG YU-CHE
HUANG YU-CHE on 19 May 2020
Commented: HUANG YU-CHE on 21 May 2020
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)));

  0 Comments

Sign in to comment.

Accepted Answer

Ameer Hamza
Ameer Hamza on 19 May 2020
Edited: Ameer Hamza on 19 May 2020
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)

Community Treasure Hunt

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

Start Hunting!