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
Walter Roberson
2017년 12월 5일
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
2017년 12월 5일
Akira Agata
2017년 12월 7일
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
2017년 12월 7일
편집: Ashley Solek
2017년 12월 7일
답변 (2개)
KSSV
2017년 12월 5일
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)
Akira Agata
2017년 12월 7일
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
카테고리
도움말 센터 및 File Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!