Reading multiple editable text boxes and writing them into a single array

1 回表示 (過去 30 日間)
Jack Georege
Jack Georege 2021 年 3 月 30 日
コメント済み: Jack Georege 2021 年 3 月 30 日
So for a project that I am doing that requires programmatic GUI development, I am trying to write a program that can read single letter inputs from multiple editable text boxes and put them into an array to be used later on. I found some code posted by Walter Roberson in 2013 that successfully created the boxes using a for loop, but I am running into errors with the part that compiles them into an array.
Here is the part that creates the text boxes:
np1 = 5;
editp1 = zeros(np1,1);
for K = 1:np1
editp1(K) = uicontrol( 'Style', 'edit', 'Units', 'normalized', 'Position', [(0.1+((K-1)*0.04)) 0.7 0.04 0.07]);
end
and here is the part that is supposed to read the inputs and put them into an array:
p1vals = cell(np1,1);
for K = 1 : np1
p1vals{1i} = get(editp1(K), 'String' );
end
When i run the code with these in place, it gives an error stating: "Array indices must be positive integers or logical values." and each cell just has "[]" in it.
For reference, I only need to read the inputs when i push a button on the GUI. Would the second block of code go in a callback function? And if so, what would that look like (on both the button's line of code and the callback function itself)

採用された回答

VBBV
VBBV 2021 年 3 月 30 日
編集済み: VBBV 2021 年 3 月 30 日
p1vals{K} = get(editp1(K), 'String' );
Why do you like to use complex variable,1i as cell array index, p1vals ?
  1 件のコメント
Jack Georege
Jack Georege 2021 年 3 月 30 日
Ok yeah that's my own fault, I'm very new to this and it's just leftover from what i copied over from the previous code. This got rid of the error, so thank you on that front.
However as to the second part of my question, How would I use this code to make it update the array p1vals when i push a button?
Thanks for the quick reply btw

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

その他の回答 (0 件)

カテゴリ

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

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by