How to assign multiple inputs from the same edit text box in MATLAB GUI into a cell array variable?

Hello. My goal is to create a cell array variable from the inputs of the edit text box. For example,
name={'first input' ; 'second input' ; ...}
Is this possible or should I try a different approach on creating that cell array variable? If it's the latter, can you help explain that? Thank you.

回答 (1 件)

name = {handles.First_editbox.String, handles.Second_editbox.String, ...}

7 件のコメント

Hi, actually I want the inputs to come from the same edit text box. For example, when the user enters 'john' and then reenters 'mike' (in the same edit text box), the output should become something like this:
name = {'john' ; 'mike'}
Can you help me with this? Thank you.
Initialize a variable. Each time the Callback on the edit box gets triggered, retrieve the variable and appened the new entry to the end of it, and save the variable away again.
I have problem with the newer input keeps overwriting the entered value before it (instead of adding it to the end of the array). Is there a way to avoid this?
Walter Roberson
Walter Roberson 2019 年 5 月 10 日
編集済み: Walter Roberson 2019 年 5 月 10 日
if ~isfield(handles, 'saved_answers')
handles.saved_answers = {};
end
this_answer = get(hObject, 'String');
handles.saved_answers{end+1} = this_answer;
guidata(hObject, handles); %update master copy
Thank you, sir. The guidata(handles) really helps.
I had a mistake there; I have fixed the line.
Noted.

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

カテゴリ

ヘルプ センター および File ExchangeEntering Commands についてさらに検索

質問済み:

2019 年 4 月 23 日

コメント済み:

2019 年 5 月 10 日

Community Treasure Hunt

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

Start Hunting!

Translated by