フィルターのクリア

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 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