필터 지우기
필터 지우기

subtracting a value from the first positive element

조회 수: 2 (최근 30일)
Nikolas Spiliopoulos
Nikolas Spiliopoulos 2017년 2월 17일
편집: Star Strider 2017년 2월 17일
hi all I have this problem: let's say I have large array and I want to subtract the first positive value that apperas (in each column) from a particular number. But only the first one, how can i do it?
thanks,
Nikolas

답변 (1개)

Star Strider
Star Strider 2017년 2월 17일
편집: Star Strider 2017년 2월 17일
For the first part, see if this does what you want:
M = randi([-5 5], 10, 5); % Create Data
[R,C] = find(M > 0); % Positive Numbers
[Cu,ia] = unique(C); % First Instance In ‘ia’
FirstPos = [Cu R(ia)] % [Column Row] Meeting Criteria
Then you can subtract those numbers from whatever number you choose.
If you want the rows and columns to be linear indices instead (this can be easier to work with), use the sub2ind function to do the conversion from the ‘FirstPos’ array.
EDIT Corrected typographical errors.

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by