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??
이전 댓글 표시
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??
채택된 답변
추가 답변 (1개)
Sudharsana Iyengar
2014년 12월 18일
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
This answer is pretty poor use of MATLAB, particularly doing this inside multiple loops (it pays to learn about vectorization when using MATLAB), and using i and j as the loop variables can lead to weird problems as these are the names of the inbuilt imaginary unit .
The OP instead proposed using indexing to allocate all of the values in one go, which is a much faster and neater solution:
B = zeros(512);
B(1:32,1:32,:) = A;
For an even faster and neater solution read my answer.
Image Analyst
2014년 12월 20일
편집: Image Analyst
2014년 12월 20일
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
2015년 1월 3일
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.
카테고리
도움말 센터 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!