필터 지우기
필터 지우기

put smaller matrix in bigger matrix

조회 수: 1 (최근 30일)
Andrea
Andrea 2012년 5월 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