Finding a specific unknown value in an array?
Mostrar comentarios más antiguos
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
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
el 5 de Dic. de 2017
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
el 7 de Dic. de 2017
Editada: Ashley Solek
el 7 de Dic. de 2017
Respuestas (2)
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
el 6 de Dic. de 2017
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
Más información sobre Resizing and Reshaping Matrices en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!