LISTBOX, PLEASE HELP ME WITH THE LISTBOX

2 ビュー (過去 30 日間)
Jules Ray
Jules Ray 2013 年 8 月 27 日
編集済み: evgeny shumsky 2019 年 9 月 10 日
Hello, i have posted some questions before about listbox but none give an answer....
my question is simple
i have this matrix:
a=1:1:10 % this is 1 2 3 4 5 6 7 8 9 10
i would like to load these numbers into a listbox, but i dont know how, must i change these numbers to char???
how ca i do this???? thanks in advance
  1 件のコメント
evgeny shumsky
evgeny shumsky 2019 年 9 月 10 日
編集済み: evgeny shumsky 2019 年 9 月 10 日
if you wont it to be one under another
Mat=[1:10];
Mat = mat2cell(num2str(Mat')); % mat=mat' converts from row vector to column vector
set(handles.listbox,'string',Mat); % listbox ->tag of the listbox
1-10.JPG

サインインしてコメントする。

採用された回答

David Sanchez
David Sanchez 2013 年 8 月 27 日
The array has to be transformed into a cell arrary:
a=1:1:10;
b=num2cell(a);
Then, send it to the popup menu:
set(handles.my_pop,'String',b);
  7 件のコメント
Jules Ray
Jules Ray 2013 年 8 月 27 日
just in case: here is the code on listbox_1 that should put the strings in the listbox_2, but is not working:
function listbox_1_Callback(hObject, eventdata, handles)
handles = guidata(hObject);
handles.output = hObject;
contents = cellstr(get(hObject,'String')); %returns stationslist contents as cell array
station_selection=char(contents{get(hObject,'Value')}) %returns selected item from stationslist
handles.statsel=station_selection;
%put profile names of profiles in LISTBOX_2
station=handles.statsel;
dirstations=handles.stationsdir;
cd(dirstations)
cd(station)
sel=(handles.statsel);
load(sprintf('%s_swaths.mat',sel));
as=nim
af=(1:1:as)
a=num2cell(af)
%a=10
set(handles.listbox_2,'String',a)
guidata(hObject, handles);
cheers
Image Analyst
Image Analyst 2013 年 8 月 28 日
What are all those things? Are any of them listboxes? Are you saying that your tag in GUIDE says listbox_1 and listbox_2 but in the code it doesn't? How are you running it? Are you clicking the green triangle in GUIDE or in MATLAB? I suspect that the figure you think you're running, you really aren't - you're running a different one.

サインインしてコメントする。

その他の回答 (1 件)

Wayne King
Wayne King 2013 年 8 月 27 日
a = inputdlg('Enter your vector');
% when dialog comes up enter, 1:10, click OK
a = str2num(cell2mat(a));
a is now a double precision vector

カテゴリ

Help Center および File ExchangeInteractive Control and Callbacks についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by