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 Kommentare

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!!

Melden Sie sich an, um zu kommentieren.

 Akzeptierte Antwort

Guillaume
Guillaume am 4 Sep. 2018
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)

Weitere Antworten (1)

dpb
dpb am 4 Sep. 2018
Bearbeitet: dpb am 4 Sep. 2018
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 Kommentare

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...

Melden Sie sich an, um zu kommentieren.

Kategorien

Produkte

Version

R2016b

Gefragt:

am 4 Sep. 2018

Bearbeitet:

dpb
am 4 Sep. 2018

Community Treasure Hunt

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

Start Hunting!

Translated by