How to store value of selected item in a drop down to a variable

조회 수: 7 (최근 30일)
Paul
Paul 2022년 12월 3일
답변: Paul 2022년 12월 5일
I am working on a live script and want to populate a drop down list with data from an Excel workbook, The data consists of two colums - names of acids and their pKa values. I can import the data as a table and from that can get column vectors. The drop down needs to display the names of the acids and their pKa values.
Am I right in thinking that it is not possible for the drop down to display two columns?
Assuming it is not possible, I am constructing a column vector containing the names of the acids with their pKa values in parentheses. I am doing this in a for ... end loop (see attached script) but is there a better/faster way of doing it?
The drop down is working nicely but I cannot change the width of the control (not the list) which looks like this . This is a potential deal breaker.
However, if I can overcome that problem, there is a further hurdle to clear. When the selection is changed I want to be able to store the pKa value of the selected item to a variable for use further down.
It does not seem possible, further down the script, to refer to the drop down or its selected value because the drop down does not have a name which can be used to reference it.

채택된 답변

Paul
Paul 2022년 12월 5일
There are three parts to this answer.
  1. The drop down can only contain one column so I put the pKa values in parentheses after the names of the acids.
  2. I cannot alter the width of the drop dow, so I just have to live with that
  3. Storing the pKa value is as easy as putting pKa = to the left of the drop down

추가 답변 (0개)

카테고리

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

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by