Error using subplot (line 301) Index exceeds number of subplots.
조회 수: 1 (최근 30일)
이전 댓글 표시
hi, guys..
i want to get the sub image of a gray scale image size 3081x4137. can i just do directly it by running the code that i saw in matlab ? fyi, i'm new to the matlab so i just try to run some code that has been created by some programmers in matlab to understand it.
actually i have tried it and i get error in 'sublot (2,2,sliceNumber)' when i run it in here :
for row = 1 : blockSizeR : rows
for col = 1 : blockSizeC : columns
row1 = row;
row2 = row1 + blockSizeR - 1;
row2 = min(rows, row2); % Don't let it go outside the image.
col1 = col;
col2 = col1 + blockSizeC - 1;
col2 = min(columns, col2); % Don't let it go outside the image.
% Extract out the block into a single subimage.
oneBlock = b(row1:row2, col1:col2);
% Specify the location for display of the image.
subplot(2, 2, sliceNumber);
imshow(oneBlock);
% Make the caption the block number.
caption = sprintf('Block #%d of 5', sliceNumber);
title(caption, 'FontSize', fontSize);
drawnow;*
what should i do, please ?
댓글 수: 0
채택된 답변
Walter Roberson
2018년 6월 8일
rowblocks = 1 : blockSizeR : rows;
colblocks = 1 : blockSizeC : columns;
numrowblocks = length(rowblocks);
numcolblocks = length(colblocks);
for rowidx = 1 : numrowblocks
row = rowblocks(rowidx);
for colidx = 1 : numcolblocks
col = colblocks(colidx);
row1 = row;
row2 = row1 + blockSizeR - 1;
row2 = min(rows, row2); % Don't let it go outside the image.
col1 = col;
col2 = col1 + blockSizeC - 1;
col2 = min(columns, col2); % Don't let it go outside the image.
% Extract out the block into a single subimage.
oneBlock = b(row1:row2, col1:col2);
% Specify the location for display of the image.
subplot(numrowblocks, numcolblocks, sliceNumber);
imshow(oneBlock);
% Make the caption the block number.
caption = sprintf('Block #%d of 5', sliceNumber);
title(caption, 'FontSize', fontSize);
drawnow;
end
end
However, I recommend you consider https://www.mathworks.com/matlabcentral/fileexchange/35085-mat2tiles--divide-array-into-equal-sized-sub-arrays
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Red에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!