Finding a specific unknown value in an array?

I created an array based on data provided...
MedianIncomeArray = [I0K_10K, I10K_14K, I15K_19K, I20K_24K,I25K_29K, I30K_34K, I35K_39K, I40K_44K,I45K_49K, I50K_59K, I60K_74K, I75K_99K,I100K_124K, I125K_149K, I150K_199K, I200KMORE]
SumIncome=sum(MedianIncomeArray, 2)
MedianValue=SumIncome/2
And found the median value, in this instance it was..
453
181
92
...
So I need to find the 453 summed value... that is the data row is such:
12 0 71 111 66 10 101 135 64 48 102 104 34 20 16 12
So I would need the 8th column.
The overall data is 2500 x 16 matrix, so is there a way to do this for each row?

4 comentarios

Walter Roberson
Walter Roberson el 5 de Dic. de 2017
When you say the 453 summed value, do you mean that you are cumsum() along the row, and want to know the index at which the cumulative sum would equal or exceed 453 ? If so then is it the index you need (8) or is it the individual entry stored at that index (e.g., 135) ?
Ashley Solek
Ashley Solek el 5 de Dic. de 2017
The index at which the cumulative sum would equal 453. I would need the index 8, as each column coincides with an income bracket, and I need to know which income bracket 453 would fall under....if that makes sense.
Akira Agata
Akira Agata el 7 de Dic. de 2017
I don't think the variable 'MedianValue' in your code is not a median value, but a mean value. For example, median value of [1,2,9] is 2, and mean value is 4. Which did you intend to calculate?
Ashley Solek
Ashley Solek el 7 de Dic. de 2017
Editada: Ashley Solek el 7 de Dic. de 2017
It is the median value, it had to be taken this way due to the format of the data. Regardless of what they represent, those are the values I'm trying to find the corresponding column to.

Iniciar sesión para comentar.

Respuestas (2)

KSSV
KSSV el 5 de Dic. de 2017
A = [5 6 8 4 3
7 6 10 9 2
8 6 4 5 4
6 1 10 5 8] ;
B = cumsum(A,2) ;
% get the index row whose cumsum is 30
[row,col,val] = find(B(:,end)==30)

1 comentario

Ashley Solek
Ashley Solek el 6 de Dic. de 2017
I do not have a consistent value that I'm looking for, it varies each row. I tried "==MedianValue" but that did not work.

Iniciar sesión para comentar.

Akira Agata
Akira Agata el 7 de Dic. de 2017
Seems that what you want to do is like this ?
% Sample data
MedianValue = [453; 181; 92];
data = randi(100, 3,16);
% Find the column number where cumsum(data,2) > MedianValue for each row
% and store them to the variable 'idx'
cData = cumsum(data,2);
idx = zeros(numel(MedianValue),1);
for kk = 1:numel(MedianValue)
idx(kk) = find(cData(kk,:) > MedianValue(kk),1);
end

Categorías

Preguntada:

el 5 de Dic. de 2017

Respondida:

el 7 de Dic. de 2017

Community Treasure Hunt

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

Start Hunting!

Translated by