# How to get specific values from matrix in column 1, based on values in other columns?

55 ビュー (過去 30 日間)
Natasha Taylor 2020 年 8 月 19 日
コメント済み: Natasha Taylor 2020 年 8 月 19 日
I have a matrix called sub01T2 (36x3 double)- this data is provided in the attachment;
0.47 0 1
11.55 1 1
17.98 1 0
25.23 1 1
38.35 1 0
65.73 2 1
119.34 2 0
153.61 2 1
200.19 2 0
282.04 1 1
309.26 0 0
I am trying to get the time values, which are in column 1 of my matrix. I have predefined the onset times by giving them column 2 value 1 and column 3 value of 1.
I was wondering how I can create a new array, that will just have the values from column 1 that has column 2 and 3 equal 1.
I tried;
narrow_onset = find(sub01T2(:,2)==1 & sub01T1(:,3)==1), but this only gives the row location, but I want the actual values from those rows from column.

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

### 採用された回答

SAA 2020 年 8 月 19 日
If I understood your question correctly this should work:
a = find(sub01T2(:,2)==1 & sub01T2(:,3)==1);
b = sub01T2(a,1);
you are getting the row that your value is in but you're not doing anyhting with it find only gives you an index.
##### 1 件のコメント表示非表示 なし
Natasha Taylor 2020 年 8 月 19 日
Yes, that is correct. I see, I didn't fully understand the find function.

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

### その他の回答 (1 件)

Binbin Qi 2020 年 8 月 19 日
clear;clc;close all
R = accumarray(sub01T2(:,2:3)+1,sub01T2(:,1),[], @(x){x});
R{2,2}
ans =
11.5500
25.2300
282.0400
##### 1 件のコメント表示非表示 なし
Natasha Taylor 2020 年 8 月 19 日
Thank you this works!!

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

### カテゴリ

Find more on Resizing and Reshaping Matrices in Help Center and File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by