Effacer les filtres
Effacer les filtres

Why this function return empty matrix?

6 vues (au cours des 30 derniers jours)
Ahmed almansory
Ahmed almansory le 30 Mai 2013
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;

Réponses (1)

Iain
Iain le 30 Mai 2013
Because val is not what you think it is. - It is probably 0.
  1 commentaire
Ahmed almansory
Ahmed almansory le 30 Mai 2013
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

Connectez-vous pour commenter.

Catégories

En savoir plus sur Convert Image Type dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by