finding unknown values in a column by using the indices (indexes) of known values.

3 ビュー (過去 30 日間)
Hello, I'm struggling a lot with some of the indexing methods. Right now I have the next matrix:
1.5000 1.7024
1.5000 1.3119
1.5000 1.3122
0.5000 0.8158
0.5000 1.1760
(it's actually a 200 by 2 matrix, but I have shortened it to make things clearer)
The values in row 1 have been provided by linspace(0.5, 1.5, 5) and the values in row 2 have been entered by the user (they are the user's reaction times, and the latter [the values in col 1] are the stimuli durations).
What I'm trying to do is to find all the user's input when the duration was 1.5000 and find the mean of those values.
So far I used: [r,c]=find(mat==1.5000), and got:
r =
1
2
3
10
17
What I need now is the values next to those rows (that is the ones in col 2) and find their mean.
Hope I was clear and concise. Thanks in advance

採用された回答

Walter Roberson
Walter Roberson 2012 年 7 月 17 日
  3 件のコメント
Ryan
Ryan 2012 年 7 月 17 日
He is warning you that find(variable == specific number) may not actually return "true" values (matches) that you're expecting because of the reasons outlined in that Matlab Wikia post. It may not apply here, but it's a good tidbit to know about to save yourself potentially from future headaches.
Juan Pablo
Juan Pablo 2012 年 7 月 17 日
Interesting, I'll take that into account, thanks

サインインしてコメントする。

その他の回答 (2 件)

Sean de Wolski
Sean de Wolski 2012 年 7 月 17 日
accumarray time! (happy time :) )
x =[1.5000 1.7024
1.5000 1.3119
1.5000 1.3122
0.5000 0.8158
0.5000 1.1760]
[y,~,idxu] = unique(x(:,1)); %indexes of each row into each unique value
y(:,2) = accumarray(idxu,x(:,2),[],@mean) %their mean
  7 件のコメント
Juan Pablo
Juan Pablo 2012 年 7 月 18 日
This helped me a lot more, wish I knew how to use all those functions!
Sean de Wolski
Sean de Wolski 2012 年 7 月 18 日
doc unique
doc accumarray
!

サインインしてコメントする。


Elizabeth
Elizabeth 2012 年 7 月 17 日
編集済み: Walter Roberson 2012 年 7 月 18 日
Probably not as efficient as those above, but this is the simplest way I always tried to do it.
j= find(row1==1.5);
for k=1:length(j)
d(k)=c(j(k));
end
meanvalues=mean(d)
  5 件のコメント
Walter Roberson
Walter Roberson 2012 年 7 月 18 日
row1 = mat(:,1);
It is a column, but Elizabeth has called it a row because you confused rows and columns when you phrased the question.
Juan Pablo
Juan Pablo 2013 年 9 月 24 日
That is true, thanks for the observation

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by