Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8225553
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T15:27:17+00:00 2026-06-07T15:27:17+00:00

I am relatively new to GUI’s in Matlab, and I have created a simple

  • 0

I am relatively new to GUI’s in Matlab, and I have created a simple GUI using GUIDE. I want to connect to a database (already defined and working!) and populate a listbox with the values from the database so the user can choose which to use (in this case they are chemical compounds). I haven’t been able to find a good tutorial or clues on how to populate the listbox in this way. So far, I have:

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 = char(result.CompoundName(i));
    end


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

    handles.output = hObject;

    % Update handles structure
    guidata(hObject, handles);

end

What would be the simplest way to populate a listbox from a database (or large array) like this? As of right now, the listbox is populated with only the first item in names, which is because somehow names contains only the first item. Although, if I just display ‘data.name’, I get the entire list of 300 items in the list!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T15:27:18+00:00Added an answer on June 7, 2026 at 3:27 pm

    I got it! So, the problem was that I was converting the data.name to a character -> originally it was a cell. Thus, I added names(i) = data(i).name; in the for loop, and removed names=data.name; It is now populated with all of the names of the compound! The working function looks like this:

    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
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm relatively new to coding; most of my work has been just simple GUI
I'm relatively new to GUI building. I want to make a GUI with a
Relatively new to C#; hopefully I'm just overlooking something simple. I have a form
I'm relatively new to .NET GUI programming using WinForms (the project I'm working on
Relatively new to using database and for some reason I can't get this 'execute'
Being relatively new to backbone.js, I've created several small tests from a simple model
I'm relatively new to GUI with Java and I have a JFrame with a
Relatively new to rails, I'm working on a simple rails app for a few
Im relatively new to the Android world but I have a quick question. I
I'm a relatively new programmer, so bear with me. I created a JFrame with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.