필터 지우기
필터 지우기

Why this function return empty matrix?

조회 수: 6 (최근 30일)
Ahmed almansory
Ahmed almansory 2013년 5월 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