matlab - Read matrix from GUI object -


i'm writing program performs gauss elimination, , want create gui this. example, if user wants input 2×2 matrix, want 4 text boxes appear in gui. problem don't know how read values these objects. code below:

n=3; b=50;    a=200; i=1:n         j=1:n         a(i,j) = uicontrol('style','edit','units','pixels',...                  'position',[b 50 50],'fontsize',20,'string','');        b = b+60;     end     b = 50;     = a-60; end  uiwait  i=1:n     j=1:n         b(i,j) = str2double(get(a(i,j),'string'));     end end 

how input data a b?

solution #1: using trigger button

one solution have trigger in ui reads data textboxes. example, can add button user must press after entering input matrix:

b = nan(n); btn = uicontrol('style','pushbutton','units','pixels',... 'position',[b 170 50],'fontsize',20,'string','read data', ...     'callback', 'for k = 1:n^2, b(k) = str2double(get(a(k),''string'')); end'); 

when user presses button, inline callback function invoked , matrix b populated. missing elements represented nan values, can verify values have been entered expression:

all(~isnan(b)) 

solution #2: responding keystrokes

another solution update matrix b user typing in data. this, add callback function textboxes so:

a(i,j) = uicontrol('style','edit','units','pixels',...     'position',[b 50 50],'fontsize',20,'string','', ...     'callback', 'b(a == gco) = str2double(get(gco, ''string''));'); 

the callback uses gco find position in matrix b matches textbox user typing into, , updates corresponding element. remember initialize b = nan(n) before double loop!


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -