Why this function return empty matrix?

6 次查看(过去 30 天)
note : the output of program is true without function
% This function take an image then devide it into block
% then reshape each block to culumn vector and put it as
% new column in new matrix(output of function).
function N=Div(m);
[rows columns ] = size(m);
%prompt the user to input the size of rows & colums in block
prompt = {'Enter block row size:','Enter block column size:'};
dlg_title = 'Input size of the block';
num_lines = 1;
def = {'8','8'};
answer = inputdlg(prompt,dlg_title,num_lines,def);
[val status] = str2num(answer{1});
%assign the user values to another variables
blockrow=val;
blockcolumn=val;
wholeBlockRows = floor(rows / blockrow);
blockVectorR = [blockrow * ones(1, wholeBlockRows), rem(rows, blockrow)];
wholeBlockCols = floor(columns / blockcolumn);
blockVectorC = [blockcolumn * ones(1, wholeBlockCols), rem(columns, blockcolumn)];
%convert the image into blocks
mCell = mat2cell(m, blockVectorR, blockVectorC);%now mCell contain all blocks
%convert each block to column vector then put the column vector as a column in new matrix n
t=1;
%intilizing of n
n=uint8(zeros(val*val,(rows*columns)/(val*val)));
for i=1:rows/blockrow
for j=1:rows/blockrow
thisBlock = mCell{i,j};
columnVector = thisBlock(:);
n(:,t)=columnVector;
t=t+1;
end
end
% return the new matrix
N=n;

回答(1 个)

Iain
Iain 2013-5-30
Because val is not what you think it is. - It is probably 0.
  1 个评论
Ahmed almansory
Ahmed almansory 2013-5-30
val not zero ,user determine the value of val
if we remove the first and last line of function the program is true
thank you for replay

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Convert Image Type 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by