Info

此问题已关闭。 请重新打开它进行编辑或回答。

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 .

1 次查看(过去 30 天)
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.

回答(1 个)

David Sanchez
David Sanchez 2013-5-28
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.

此问题已关闭。

Community Treasure Hunt

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

Start Hunting!

Translated by