How to select a regionprops from a popup menu in a GUI?

조회 수: 2 (최근 30일)
Meshooo
Meshooo 2014년 1월 23일
편집: Meshooo 2014년 1월 23일
Dear all,
I am building one GUI which include a popup menu for a 'regionprops' function that I need. I am trying to call the type of 'regionprops' after clicking a push button but it is not working. My code is as follows:
popup_2_Value = get(handles.popupmenu2, 'Value');
if popup_2_Value == 1
RegPropType = 'Area';
elseif popup_2_Value == 2
RegPropType = 'MajorAxisLength';
elseif popup_2_Value == 3
RegPropType = 'MinorAxisLength';
elseif popup_2_Value == 4
RegPropType = 'Perimeter';
elseif popup_2_Value == 5
RegPropType = 'Orientation';
end
%
X = im2bw(I); %binary image of the input
CC = bwconncomp(X); %Connected components
mal = regionprops(CC,'RegPropType'); % normal code format is --> mal = regionprops(CC,'Area');
mal = vertcat(mal(:).RegPropType); % normal code format is --> mal = vertcat(mal(:).Area);
This error message appears "Error using regionprops>getPropsFromInput"
Any idea how to solve such problem?
With kind regard,
Meshoo

채택된 답변

ES
ES 2014년 1월 23일
From what I see, you should have done
mal = regionprops(CC,RegPropType)
instead of
mal = regionprops(CC,'RegPropType');%Note the missing quotes
Since the variable RegPropType has the required string like 'area' or ' Perimeter' etc. When you pass as 'RegPropType', this string itself is passed, and not the value inside the variable RegPropType.
  댓글 수: 2
Meshooo
Meshooo 2014년 1월 23일
Yes, you are right for the first part. As you said it should be
mal = regionprops(CC,RegPropType)
But how can we do the following second part
mal = vertcat(mal(:).RegPropType);
Thank you very much.
ES
ES 2014년 1월 23일
you can do an eval.
mal = eval(['vertcat(mal(:).',RegPropType]);

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Fluid Dynamics에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by