put smaller matrix in bigger matrix
2 views (last 30 days)
Show older comments
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 Comments
Rahul
on 30 May 2012
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..
Accepted Answer
Andrei Bobrov
on 30 May 2012
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 Comments
More Answers (0)
See Also
Categories
Find more on Logical in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!