How to extract a vector from a large matrix by ind

2019-06-03 17:35发布

I am stucked with this issue in MATLAB for long now and I hope to find a help here!

I have a very large matrix with 4 vectors in it (each vector is a column) and 72300 rows .. the first column/vector is the index of the data .. so it is something like this: (example is simplified)

Index, Info1  Info2  Info3
1      2      1      1
1      4      5      3
1      2.5    1.3    8
2      1      4      7
2      4      6      9
2      12     3      7
3      2      6      6
3      2      1      4
3      1      4      7

Q1> How can I extract all Info2 with the index==3 from this matrix?

Q2> Is there any method to rearrange the matrix to be like this?

Index,   Info1,   Info2 Info3   Index   Info1   Info 2  Info 3
 1                              2

and so on ..

I hope to find some help from you guys and many many thanks in advance..

kind regards,

2条回答
一纸荒年 Trace。
2楼-- · 2019-06-03 18:27

Q1 :

For you question 1, I use a simple example because I don't have your variable name.

idx = find( VectorName(:,1) == 3 ) % Find in all row at column 1 where = 3 (Index)

After you have the index of all row where index == 3. So extract info2 value

AllInfo2 = VectorName(idx,3); % Get all value where row == idx and column = 3 (Info2)
查看更多
▲ chillily
3楼-- · 2019-06-03 18:35

Q1 >> x = A(A(:1)==3,3); % Info2 for Index==3

Q2 >> B = reshape(A.',1,[]); %Flatten A along the rows

查看更多
登录 后发表回答