making a vector of cells

1 view (last 30 days)
Rotem Stahl
Rotem Stahl on 5 Jan 2021
Commented: Rotem Stahl on 6 Jan 2021
i have a project making a GUI i work on
my GUI has to open a CSV file that had 5000+ rows of info about countries and allow the user to plot info by choise
for example - choose USA, then plot popolation and birthrate (as X and Y)
in my CVS the first column is country, when i read it with readtable i have it as cells that have a string.
i want to create a short vector that only have the names once to use it in my Popupmenu as the list of countries
how can i poll the info easily once to a cell vectore that i can later use as a long string?
thank you!

Accepted Answer

dpb
dpb on 5 Jan 2021
Probably good choice would be to convert the country string/column in the table into a categorical variable; makes for looking for a match simpler than using string comparisons by the "==" operator, for example.
To create the list for your UI,
countriesList=unique(tYourTable.Country);
This will give you an alphabetically-sorted list automagically.
  1 Comment
Rotem Stahl
Rotem Stahl on 6 Jan 2021
first of all, thank you! i did not know this function existed!
a follow up question, if i may -
i am now trying to make the cell array be what you see in the popupmenu of the GUI
set(handle.country_menu,'string',countriesList);
gives me an answer:
The class handle has no property or method named 'country_menu'.
do you know what am i doing wrong?
thank you!
Rotem

Sign in to comment.

More Answers (0)

Categories

Find more on Migrate GUIDE Apps in Help Center and File Exchange

Products


Release

R2015a

Community Treasure Hunt

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

Start Hunting!