Why this function return empty matrix?

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 日

0 投票

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

サインインしてコメントする。

カテゴリ

質問済み:

2013 年 5 月 30 日

Community Treasure Hunt

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

Start Hunting!

Translated by