Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Ui table data

Subject: Ui table data

From: saurabh Srivastava

Date: 3 May, 2010 22:34:09

Message: 1 of 6

Dear all
I am using set(uitable,'data',data) command to put the data in table but it will set the data in entire table or in 1st n colomn. What I want to do is replace specific data in a particular column without affecting the other column data. For example there is N*3 data set in table; I want to change the entire data of 3rd column only. How It can be done...?

Subject: Ui table data

From: Walter Roberson

Date: 3 May, 2010 22:57:39

Message: 2 of 6

saurabh Srivastava wrote:
> I am using set(uitable,'data',data) command to put the data in table but it will set the data in entire table or in 1st n colomn. What I want to do is replace specific data in a particular column without affecting the other column data.

No Matlab-level mechanism is supplied for that, at least up through 2008b.

It would not surprise me if there was a Java method that could do what you
want, but I have never looked at the Java level of a uitable.

Subject: Ui table data

From: Yair Altman

Date: 4 May, 2010 07:00:10

Message: 3 of 6

Walter Roberson <roberson@hushmail.com> wrote in message <hrnkd7$j4j$1@canopus.cc.umanitoba.ca>...
> saurabh Srivastava wrote:
> > I am using set(uitable,'data',data) command to put the data in table but it will set the data in entire table or in 1st n colomn. What I want to do is replace specific data in a particular column without affecting the other column data.
>
> No Matlab-level mechanism is supplied for that, at least up through 2008b.
>
> It would not surprise me if there was a Java method that could do what you
> want, but I have never looked at the Java level of a uitable.


uitable returns two arguments: a handle to the created table (a com.mathworks.hg.peer.UitablePeer Java object wrapped within a Matlab handle) and an undocumented second optional argument holding a handle to the Matlab GUI container of the created table. These two arguments are exactly the two arguments returned from the javacomponent function.

Note that the table object returned by uitable is not actually a Java object but rather a Matlab handle object that references the Java object. Because of this, I usually call the returned objects mtable, to differentiate it from the underlying Java object, which I call jtable:

mtable = uitable(…);
jtable = mtable.getTable;
jtable = get(mtable, 'table'); % an alternative method

It is important to understand that mtable, like any Matlab object, uses 1-based indexing, whereas jtable, like any Java object, uses 0-based indexing. So the first column (or row or anything) is 1 in mtable and 0 in jtable. Forgetting this rule is an endless source of bugs… Having understood this, we can now turn to the question of how to set data in the table:

jtable.setValueAt(myValue,row,col); % row,col start at 0

We can also set the entire data table at once, useful for performance on large data sets:

jtable.getModel.setDataVector(data); % data = java.util.Vector
data = jtable.getModel.getDataVector;

Yair Altman
http://UndocumentedMatlab.com

Subject: Ui table data

From: Corey Kelly

Date: 28 May, 2010 04:46:04

Message: 4 of 6

"Yair Altman" <altmanyDEL@gmailDEL.comDEL> wrote in message <hroglq$nfm$1@fred.mathworks.com>...
> Walter Roberson <roberson@hushmail.com> wrote in message <hrnkd7$j4j$1@canopus.cc.umanitoba.ca>...
> > saurabh Srivastava wrote:
> > > I am using set(uitable,'data',data) command to put the data in table but it will set the data in entire table or in 1st n colomn. What I want to do is replace specific data in a particular column without affecting the other column data.
> >
> > No Matlab-level mechanism is supplied for that, at least up through 2008b.
> >
> > It would not surprise me if there was a Java method that could do what you
> > want, but I have never looked at the Java level of a uitable.
>
>
> uitable returns two arguments: a handle to the created table (a com.mathworks.hg.peer.UitablePeer Java object wrapped within a Matlab handle) and an undocumented second optional argument holding a handle to the Matlab GUI container of the created table. These two arguments are exactly the two arguments returned from the javacomponent function.
>
> Note that the table object returned by uitable is not actually a Java object but rather a Matlab handle object that references the Java object. Because of this, I usually call the returned objects mtable, to differentiate it from the underlying Java object, which I call jtable:
>
> mtable = uitable(…);
> jtable = mtable.getTable;
> jtable = get(mtable, 'table'); % an alternative method
>
> It is important to understand that mtable, like any Matlab object, uses 1-based indexing, whereas jtable, like any Java object, uses 0-based indexing. So the first column (or row or anything) is 1 in mtable and 0 in jtable. Forgetting this rule is an endless source of bugs… Having understood this, we can now turn to the question of how to set data in the table:
>
> jtable.setValueAt(myValue,row,col); % row,col start at 0
>
> We can also set the entire data table at once, useful for performance on large data sets:
>
> jtable.getModel.setDataVector(data); % data = java.util.Vector
> data = jtable.getModel.getDataVector;
>
> Yair Altman
> http://UndocumentedMatlab.com

I'm having a similar problem and would like to make use of jtable. My gui was started in GUIDE, so I don't have an explicit call to uitable() anywhere. I've tried making the following call in the CreateFcn for the uitable:
handles.jtable = hObject.getTable;

but I'm getting the error

??? Attempt to reference field of non-structure array.

How would I get the handle for the uitable?

Subject: Ui table data

From: Yair Altman

Date: 12 Jun, 2010 20:45:09

Message: 5 of 6

"Corey Kelly" <ckelly01@uoguelph.ca> wrote in message
> I'm having a similar problem and would like to make use of jtable. My gui was started in GUIDE, so I don't have an explicit call to uitable() anywhere. I've tried making the following call in the CreateFcn for the uitable:
> handles.jtable = hObject.getTable;
>
> but I'm getting the error
>
> ??? Attempt to reference field of non-structure array.
>
> How would I get the handle for the uitable?

Answered here:
http://www.mathworks.com/matlabcentral/newsreader/view_thread/284435#753987

Yair Altman
http://UndocumentedMatlab.com

Subject: Ui table data

From: Corey Gravelle

Date: 19 Sep, 2010 06:37:05

Message: 6 of 6

% Thanks Yair, useful stuff!

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us