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
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
Ashley Solek 2017 年 12 月 5 日
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 件のコメント

Ashley Solek
Ashley Solek 2017 年 12 月 6 日
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 ExchangeResizing 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