How to repeat the content of a listbox in gui matlab?

1 回表示 (過去 30 日間)
Ahmed Elsherif
Ahmed Elsherif 2019 年 1 月 7 日
回答済み: Ahmed Elsherif 2019 年 1 月 8 日
Hello,
In my code, I have an edit box where the user has to enter a value in this edit box, afterward this entered value is transferred to a list box. My list box has to be populated with many rows and one column, say 1000 rows. So, what I need is to repeat the printed value from the edit box 1000 times. Is there a way for doing this?
I get the data from my edit box as:
data=get(handles.edit_T,'string');
Then to transfer it to the list box I have:
data=[data ; cellstr('')];
set(handles.edit_Texp,'string', data);
I tried to use a 'for' loop like:
for i=1:1000
data=[data ; cellstr(i)];
set(handles.edit_Texp,'string', data);
end
But the first line in the listbox is correct and after that it shows '2'
Would someone tell me how to do this?
Thanks in advance,
Ahmed

採用された回答

Jan
Jan 2019 年 1 月 7 日
編集済み: Jan 2019 年 1 月 7 日
Maybe you mean:
data = get(handles.edit_T,'string');
data = cellstr(data);
set(handles.edit_Texp, 'string', repmat(data, 1000, 1));
cellstr(i) converts i to a cell string. Setting the String property 1000 times is a waste of time.
  1 件のコメント
Ahmed Elsherif
Ahmed Elsherif 2019 年 1 月 8 日
Thank you very much. It works fine!

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

その他の回答 (1 件)

Ahmed Elsherif
Ahmed Elsherif 2019 年 1 月 8 日
One more question. I am trying to read the first column of a text file and print it in a list box (tauexp) by using:
[filename pathname] = uigetfile('*.txt', 'File Selector]');
fullpathname=strcat(pathname , filename);
x = fileread(fullpathname);
tScan = textscan(x, '%s %f %s','headerlines',1);
newScan = tScan{:};
data=newScan(:,1); % to read only the 1st column
set(handles.edit_tauexp,'string',data);
What I got is a mixture of data in the first column with the data in the 4th column. Could you please tell me why and how to fix this?

カテゴリ

Help Center および File ExchangeMigrate GUIDE Apps についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by