How to find the first value coordinate(the minimum non-zero x coordinate) in each row?
조회 수: 2 (최근 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)));
댓글 수: 0
채택된 답변
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)
To smooth a signal use smoothdata(): https://www.mathworks.com/help/releases/R2020a/matlab/ref/smoothdata.html
댓글 수: 3
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
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 Exchange에서 Scatter Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!