MATLAB Answers


Why this function return empty matrix?

Asked by Ahmed almansory on 30 May 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
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
%intilizing of n
for i=1:rows/blockrow
    for j=1:rows/blockrow
        thisBlock = mCell{i,j};
        columnVector = thisBlock(:);
% return the new matrix



No products are associated with this question.

1 Answer

Answer by Iain
on 30 May 2013

Because val is not what you think it is. - It is probably 0.

  1 Comment

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

Join the 15-year community celebration.

Play games and win prizes!

Learn more
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!