Only keep positve values from a matrix and plot the last of those values.

조회 수: 3 (최근 30일)
Hello
I have a matrix (1001x50001) and I want to plot the last potive value of each column. The problem is that the last positve value changes position every now and then to the next row.
How do I plot a graph of these value?
I have tried to save all the positve elements from the matrix as a new variable, but I end up with a very long vector.
sPositive = s(s>0)

채택된 답변

Ameer Hamza
Ameer Hamza 2020년 5월 1일
편집: Ameer Hamza 2020년 5월 1일
try this
s = randn(100, 200); % random vector
[~,r] = max(flipud(s)>0);
r = size(s,1)-r+1;
c = 1:size(s,2);
idx = sub2ind(size(s), r, c);
s_positive = s(idx);
s_positive is the first positive value in each column.
  댓글 수: 8
Mikkel Christensen
Mikkel Christensen 2020년 5월 1일
That's amazing, that did the trick.
Thank you very much!!!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Descriptive Statistics and Visualization에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by