필터 지우기
필터 지우기

Get index of specific string in popup

조회 수: 1 (최근 30일)
Joe Nunes
Joe Nunes 2011년 2월 26일
Hello,
I have a popup populated with Strings.
Now, I want to set the Value (index) corresponding to the string in that value. Example. If the popup has the values 'linear', 'polynomial', 'spline'.
If I want polynomial selected I want to set the current value to 2. But how to do it dynamically?
Thanks in advance Regards

채택된 답변

Matt Fig
Matt Fig 2011년 2월 26일
L = strmatch('polynomial',get(ls,'string'));
set(ls,'value',L)
  댓글 수: 1
Jan
Jan 2011년 2월 27일
STRMATCH is deprecated. STRCMP will be supported in the future and is faster.

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

추가 답변 (1개)

Walter Roberson
Walter Roberson 2011년 2월 28일
The way I handle this in my code is to have a cell array of readable names, and a cell array of the full corresponding strings. The String parameter of the popup gets populated from the cell array of the full corresponding strings, and I build a struct() out of the combination of the cell array of readable names and num2cell(1:TheNumberOfStrings) . Then I use the fieldnames of the struct in place of the values.:
interpfields = {'lin', 'poly', 'spline'};
interpstrings = {'linear', 'polynomial', 'spline'};
t = [interpfields(:).'; num2cell(1:length(interpfields))]
interpcodes = struct(t{:});
interppop = uicontol('Style','popup', 'String', interpstrings);
set(interppop, 'Value', interpcodes.poly);
With this method, you do not need to search each time, and you do not need to change the code if you decide to change the exact phrasing of the strings.
  댓글 수: 1
Joe Nunes
Joe Nunes 2011년 2월 28일
That is a good idea. Thanks for the help

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

카테고리

Help CenterFile Exchange에서 Characters and Strings에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by