2012-07-15 2 views
1

저는 Matlab의 GUI가 비교적 새롭고 GUIDE를 사용하여 간단한 GUI를 만들었습니다. 데이터베이스 (이미 정의되고 작동 중입니다!)에 연결하고 데이터베이스의 값으로 목록 상자를 채워서 사용자가 사용할 항목 (이 경우에는 화학 화합물)을 선택할 수 있습니다. 나는 이런 식으로 목록 상자를 채우는 방법에 대한 좋은 자습서 나 단서를 찾을 수 없었다. 지금까지 나는 다음과 같은 것을 가지고있다 :데이터베이스 값에서 Matlab GUI 목록 상자 채우기

데이터베이스 (또는 대형 배열)에서 이와 같은 목록 상자를 채우는 가장 간단한 방법은 무엇입니까? 현재 목록 상자에는 이름의 첫 번째 항목 만 채워져 있는데, 이는 이름에 첫 번째 항목 만 포함되어 있기 때문입니다. 하지만 'data.name'만 표시하면 목록에 300 개의 항목 전체 목록이 표시됩니다.

답변

1

알았어! 그래서 문제는 data.name을 원래 문자 인 문자로 변환한다는 것입니다. 따라서 for 루프에 names(i) = data(i).name;을 추가하고 제거했습니다. names=data.name; 이제 모든 화합물 이름이 채워집니다! 작동 함수는 다음과 같습니다.

function load_listbox(hObject,handles) 

    conn = database('antoine_db','',''); 
    setdbprefs('datareturnformat','structure'); %sets the db preferences to a structure 
    query = 'SELECT ID,"Compound Name" FROM antoine_data ORDER BY ID'; 

    result = fetch(conn,query); 

    %%The following creates a structure containing the names and ID's 
    %%of everything in the database 
    data = struct([]); 
    for i=1:length(result.ID) 
     data(i).id = result.ID(i); 
     data(i).name = (result.CompoundName(i));  %this is a cell 
     names(i) = data(i).name; 
    end 



    handles.compounds = names; 
    set(handles.listbox1,'String',handles.compounds,'Value',1); 

handles.output = hObject; 

% Update handles structure 
guidata(hObject, handles); 

end