put smaller matrix in bigger matrix

2 次查看(过去 30 天)
Hello I have row=[1 2 5 4 3 6] and column=[5 7 3 4 8 14]. I want to select and put each Q(row,column) in a new data. for example Q(row(1),column(1)), Q(row(2),column(2)), and Q(row(3), column(3)), .. . I want to put these Q in a new matrix P. Can anybody help me? something like this that does not work: P=Q((1:row),(1:column)) or P=Q(row,column)
  2 个评论
Rahul
Rahul 2012-5-30
How do you want output
q= 1 5
2 7
5 3
4 4
3 8
6 14
Is this how your output q should look like? give an example of your output..
Andrea
Andrea 2012-5-30
No. These are the indicators of row and col. for example Q(row(1),column(1))=10, Q(row(2),column(2))=25 , and Q(row(3), column(3))=12 and ....
I want to to put them in a matrix P=zeros(size(Q)). in the way their arrangement will not change.
please see this example:
Q =
1 2 3 4 5 6
3 2 1 6 5 4
0 1 10 5 5 1
8 7 9 8 1 0
row = [2 3];
col= [ 4 5 6];
P =
6 5 4 0 0 0
5 5 1 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
and then, I want to select another sub-matrix (with different size such as 1*2) and put it right next to the first part in Matrix P.

请先登录,再进行评论。

采纳的回答

Andrei Bobrov
Andrei Bobrov 2012-5-30
eg:
Q = randi(456,10,15);
row=[1 2 5 4 3 6];
column=[5 7 3 4 8 14];
P = Q(sub2ind(size(Q),row,column));
EDIT
p = Q(row,column);
P = zeros(size(Q));
P(1:numel(row),1:numel(column)) = p;
  3 个评论
Andrea
Andrea 2012-5-30
Just one issue occurs. I need matrix p to have Q(row(1),column(1)), Q(row(1),column(1)), Q(row(2),column(2)), Q(row(3),column(3)), Q(row(4),column(4)), Q(row(5),column(5)), and Q(row(6),column(6)). But what (p = Q(row,column);) give me is a 6*6 matrix in this way Q(row(1),column(1)), Q(row(1),column(2)), Q(row(1),column(3)), Q(row(1),column(4)), and..... How can solve this problem?
Andrei Bobrov
Andrei Bobrov 2012-5-31
Hi Andrea! Please see my answer (befor 'EDIT')

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by