Error using subplot (line 301) Index exceeds number of subplots.

조회 수: 1 (최근 30일)
Ade Aulya
Ade Aulya 2018년 6월 8일
댓글: Ade Aulya 2018년 6월 8일
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 ?

채택된 답변

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Red에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by