I have 32x32 matrix...But I want to make this a 512x512 matrix with the same element as in the 32x32 matrix..and the rest of which would be zero in 512x512 matrix.. how do i do it??
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Sanik
am 18 Dez. 2014
Kommentiert: Image Analyst
am 3 Jan. 2015
I have 32x32 matrix...But I want to make this a 512x512 matrix with the same element as in the 32x32 matrix..and the rest of which would be zero in 512x512 matrix.. how do i do it??
0 Kommentare
Akzeptierte Antwort
Stephen23
am 18 Dez. 2014
Bearbeitet: Stephen23
am 20 Dez. 2014
There is no need to waste time or space with loops or even copying the data from one matrix to another. Try this instead:
A = rand(32);
A(512,512) = 0;
The first line creates a matrix of size 32x32, the second line allocates the value zero to the element at position (512,512). Of course there is no such element, so MATLAB enlarges the matrix, and automatically fills all of the missing values with zero.
0 Kommentare
Weitere Antworten (1)
Sudharsana Iyengar
am 18 Dez. 2014
A=32x32 matrix
B=zeros(512)
for i= 1:32
for j=1:32
B(i,j)=A(i,j)
end
end
try this
3 Kommentare
Image Analyst
am 20 Dez. 2014
Bearbeitet: Image Analyst
am 20 Dez. 2014
sanik's "Answer" moved here:
Thank you so much...I just now tried this one:
B=zeros(512);
A=32x32;
B(1:32,1:32,:)=A;
and yea this is working too. Thanks...
Image Analyst
am 3 Jan. 2015
I accepted Stephen's answer for you, since this was his idea. But I agree with him that the "trick" he used in his answer is preferable, though a little less explicit and obvious. Please give him reputation points by voting for his answer.
Siehe auch
Kategorien
Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!