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

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) ?
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 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
Ashley Solek 2017년 12월 7일
편집: Ashley Solek 2017년 12월 7일
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.

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

답변 (2개)

KSSV
KSSV 2017년 12월 5일

0 개 추천

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

I do not have a consistent value that I'm looking for, it varies each row. I tried "==MedianValue" but that did not work.

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

Akira Agata
Akira Agata 2017년 12월 7일

0 개 추천

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에 대해 자세히 알아보기

질문:

2017년 12월 5일

답변:

2017년 12월 7일

Community Treasure Hunt

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

Start Hunting!

Translated by