From: blue on 14 Jun 2010 12:29 Hello everyone, I'm a beginner in Matlab. I try to make a simple GUI with a uitable, and a pushbutton, and I want to make with this object following thing: I want to insert the data of table in a matrix, when I push the button (the columns of the tabele ineditable). Example: I have one table with "n" (value of "n" is finit, may be 10 or 20 ... or 60) rows and 2 columns. After I insert the value in the table, when I push the button, the value of table insert automatic in the matrix nx2 (10x2 or 20x2.....60x2). On the callback function of the bushbuton I have data = get(handles.uitable1,'Data'), how insert data inthe matrix? Thank you very much!
From: Walter Roberson on 14 Jun 2010 12:45 blue wrote: > On the callback function of the bushbuton I have > data = get(handles.uitable1,'Data'), how insert data inthe matrix? newdata = zeros(size(data)+[1,0]); newdata(1:insertafterrow,:) = data(1:insertafterrow,:); newdata(insertafterrow+1,:) = additionaldata; newdata(insertafterrow+2:end,:) = data(insertafterrow+1:end,:); set(handles.uitable1,'Data',newdata);
From: blue on 14 Jun 2010 13:01 Walter Roberson <roberson(a)hushmail.com> wrote in message <%0tRn.58280$h57.42856(a)newsfe22.iad>... > blue wrote: > > > On the callback function of the bushbuton I have > > data = get(handles.uitable1,'Data'), how insert data inthe matrix? > > newdata = zeros(size(data)+[1,0]); > newdata(1:c,:) = data(1:insertafterrow,:); > newdata(insertafterrow+1,:) = additionaldata; > newdata(insertafterrow+2:end,:) = data(insertafterrow+1:end,:); > set(handles.uitable1,'Data',newdata); Thanks for answare mr. Walter Robersonm but i don't undestand exactly what does this cod. You can explain pllease... ?
From: Walter Roberson on 14 Jun 2010 14:30 blue wrote: > Walter Roberson <roberson(a)hushmail.com> wrote in message > <%0tRn.58280$h57.42856(a)newsfe22.iad>... >> blue wrote: >> >> > On the callback function of the bushbuton I have >> > data = get(handles.uitable1,'Data'), how insert data inthe matrix? >> >> newdata = zeros(size(data)+[1,0]); >> newdata(1:c,:) = data(1:insertafterrow,:); >> newdata(insertafterrow+1,:) = additionaldata; >> newdata(insertafterrow+2:end,:) = data(insertafterrow+1:end,:); >> set(handles.uitable1,'Data',newdata); > > Thanks for answare mr. Walter Robersonm but i don't undestand exactly > what does this cod. You can explain pllease... ? You wanted to insert data into a table. I took the "insert" to mean somewhere in the middle of the table, as people would say "add" or "append" if they meant at the end. The code I gave handles inserting a row by creating a new matrix with one more row, copying the data before the insertion point to the new matrix, setting the new row to be whatever you wanted, and then copies the remainder of the old data to below the inserted row. After that, it activated the new data by setting the uitable Data property to be the new data. Adding a new column instead of row would be a little more complex as you would also have to add a new column heading describing the kind of data. Ah, I just noticed a problem in the above code: it will only work if your table is a pure numeric table. If your table is a cell array, then newdata = cell(size(data)+[1,0]); newdata(1:c,:) = data(1:insertafterrow,:); newdata(insertafterrow+1,:) = additionaldata_cell_array; newdata(insertafterrow+2:end,:) = data(insertafterrow+1:end,:); set(handles.uitable1,'Data',newdata);
|
Pages: 1 Prev: Simple hack to get $500 to your home. Next: HTML to Text |