Row-by-row analysis after establishing a threshold value

Hi community,
I have a matrix of 3 columns X a lot of rows. My goal is to do an analysis of each row depending on a general threshold value. Values contained in cells ranged from 0 to 1, and I want to find in which of these 3 columns is the higher value, with the condition that the higher value must be over the threshold value. The analysis I plan to do need to test several possible threshold values.
However, there are a couple of situations that may occur:
1) All values are under the threshold value: In this case I need a zero as output. 2) There is more than one value over the threshold value: I need a zero as output as well.
For example, given a threshold value of 0.5, applied to this matrix:
[0.55 0.45 0.55;0.65 0.75 0.85;0.35 0.95 0.45;0.85 0.15 0.25;0.35 0.25 0.15;0.45 0.45 0.35]
The output expected is:
[0;0;2;1;0;0]
In the first two rows there is a "multiple assignment" situation (there is more than one value over the threshold value), then a 0 is the final assignment. Rows 3 and 4 have only one value over threshold value, and they are located in columns 2 and 1, respectively. Finally, rows 5 and 6 contain all values under threshold value, in this manner a 0 must be assigned (this would be an "unassigned" situation).
Thank you very much for your collaboration!!!!

댓글 수: 2

What are the threshold values?
It is each value that is intended to be tested. The values contained in cells ranged from 0 to 1, so the different values that are intended to be tested are between 0 and 1 too. Thanks!!

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

 채택된 답변

Guillaume
Guillaume 2018년 9월 4일
Another way to obtain the same:
A = [0.55 0.45 0.55;0.65 0.75 0.85;0.35 0.95 0.45;0.85 0.15 0.25;0.35 0.25 0.15;0.45 0.45 0.35];
t = 0.5;
abovethresh = A >= t;
[~, idx] = max(abovethresh, [], 2);
idx = idx .* (sum(abovethresh, 2) == 1)

추가 답변 (1개)

dpb
dpb 2018년 9월 4일
편집: dpb 2018년 9월 4일
A=[0.55 0.45 0.55;0.65 0.75 0.85;0.35 0.95 0.45;0.85 0.15 0.25;0.35 0.25 0.15;0.45 0.45 0.35];
T=0.5;
iUnOv=all(A<T,2) | sum(A>T,2)>1; % those that aren't to consider in max()
A(iUnOv,:)=0; % clear them
[~,B(~iUnOv)]=max(A(~iUnOv,:),[],2); % find max location for the others
>> B
B =
0
0
2
1
0
0
Look up "logical addressing"...
NB: The above excludes ==T(hreshold) from both tests. Include the '=' in the appropriate test condition if is to be inclusive on either side.

댓글 수: 2

Hi dpb. Thank you very much for your answer. One observation: I´m having a problem regarding the ix input in the last row (Undefined function or variable ix). I guess probably I´m doing something wrong but now is not working this last command. Any help would be very valuable. Thank you very much.
Oh, I recast two variables into one when I posted the Answer from initial code at command line and didn't follow thru completely, my bad.
I fixed the LH side, but not the RH side. What was ix is iUnOv now. Corrected the Answer, too...

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

카테고리

도움말 센터File Exchange에서 Matrix Indexing에 대해 자세히 알아보기

제품

릴리스

R2016b

질문:

2018년 9월 4일

편집:

dpb
2018년 9월 4일

Community Treasure Hunt

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

Start Hunting!

Translated by