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

To resolve issues starting MATLAB on Mac OS X 10.10 (Yosemite) visit: http://www.mathworks.com/matlabcentral/answers/159016

i m working on gui. i have initialize one matrix at the starting n now i want to use it in switch statement with variation .

Asked by pammy on 28 May 2013

i've a one matrix named B = zeros(BmatRows, BmatCols);

 here BmatRows remains the same in all of the cases but i want variation in BmatCols.

the code on pushButton is :

BmatRows=(rowImg-(blockSizeR-1))*(colImg-(blockSizeC-1));
BmatCols=blockSizeR*blockSizeC; 
B=zeros(BmatRows,BmatCols);
for row=1:incrR:rowImg-(blockSizeR-1)
      rowStart=row;
      rowEnd=row+(blockSizeR-1);
      %rowEnd=row-blockSizeR+1;
  for col=1:incrC:colImg-(blockSizeC-1)
      colStart=col;
      colEnd=col+(blockSizeC-1);
      oneBlock=grayImage(rowStart:rowEnd,colStart:colEnd);
        % Determine the selected data set.
        str = get(handles.popupmenu1,'String');
        val = get(handles.popupmenu1,'Value');
        % Set current data to the selected data set.
        switch str{val};
            case 'Intensity' % User selects Intensity.
                vecOneBlock1= reshape(oneBlock,1,numel(oneBlock));
                B(index,:)=vecOneBlock1;
            case 'Entropy' % User selects GLCM.
                Entropy=entropy(oneBlock);
                vecOneBlock2= reshape(Entropy,1,numel(Entropy));
                B(index,1)=vecOneBlock2;
        end
    end
end

here i've mentionaed only two cases but i 've number of cases with varying columns.

case intensity works well BmatCols is correct.

in case of entropy here i want the BmatCols to be 1 i.e i want only one column in B matrix. here in the above code i wrote B(index,1), what it does is it only fills the first column and rest of the columns with 0s this i dont want.

in case of Blur Moment i want the BmatCols to be 6 i.e i want total of 6 columns.

plz tell me how to do so.

0 Comments

pammy

Products

No products are associated with this question.

1 Answer

Answer by David Sanchez on 28 May 2013

If you want to get rid of columns you can use the following example:

B= rand(3); % 3x3 matrix
B=B(:,1) % 3x1 matrix

In your entropy case, you can do the following:

vecOneBlock2 = reshape(Entropy,1,numel(Entropy));
B = vecOneBlock2;

You will not see your useless columns of zeros.

0 Comments

David Sanchez

Contact us