programmatical access to current selection in uitable under uifigure

38 visualizaciones (últimos 30 días)
Hi,
Is there any way to:
1) check which cells are currently selected in a uitable (under the new uifigures, I'm aware of the methods available for standard figures).
2) programmatically impose a selection...
Any comment welcome!
Daniel

Respuesta aceptada

Xiangrui Li
Xiangrui Li el 20 de Sept. de 2020
Editada: Xiangrui Li el 20 de Sept. de 2020
As mentioned in my previous post, Mathworks informed me the issue has been addressed since R2020a, but I did not find any documentation for it, neither in R2020b. After some hacks, it turns out they indeed addressed the issue, but those related properties are hidden and unavailable in the help document.
Here are several related properties (all hidden till R2020b):
h = uitable(uifigure, 'Data', magic(3)); % set up a table
h.Selection = [1 2]; % select a cell programmatically
h.SelectionType % default 'cell', could be 'row' or 'column'
h.Multiselect % default 'on', could be 'off', but will interact with SelectionType
Note if h.SeletionType is 'row', h.Selection, as well as event.Indices in callback, will be scalar.
  1 comentario
Arabarra
Arabarra el 10 de Dic. de 2020
Wonderful! Thanks, Xiangrui!
I'm still on 2020a, so that I could not see the hidden properties. If they have more hidden goodies, I hope they reveal them soon.

Iniciar sesión para comentar.

Más respuestas (2)

David Hill
David Hill el 15 de Jun. de 2020
This shows how to show or assign the current indices selected. Not sure if you can programmatically impose selection. It appears that Indices is read only.
t = readtable('patients.xls');
vars = {'Age','Systolic','Diastolic','Smoker'};
t = t(1:15,vars);
fig = uifigure;
uit = uitable(fig,'Data',t);
uit.CellSelectionCallback=@selection;
function selection(src,event)
k=event.Indices
end
  1 comentario
Arabarra
Arabarra el 15 de Jun. de 2020
thanks David. In my CellSelectionCallback I have added a line that stores the data of the last selection (as read from the event), so that I can access it from outside of the callback. It solves my problem, although it is still annoying.
For 2)... well, there is no obvious way to do this, I was wondering if somebody has found some backdoor, in the fashion that Yair Altman's jtable used to extend the usability of uitable in the standard figures.

Iniciar sesión para comentar.


Xiangrui Li
Xiangrui Li el 29 de Ag. de 2020
Editada: Xiangrui Li el 29 de Ag. de 2020
In R2019b or earlier, there is no way to programmatically select a cell or row. This was confirmed with Mathworks and I requested the feature on October 20, 2019.
I tried a dumb way to simulate the selection: use uistyle to highlight a row of interest, and construct event.Indices for a call to CellSelectionCallback. It kind of works, except that the previously really selected row still has light blue background.
On August 28, 2020, I got a notice form Mathworks: “We are pleased to inform you that the issue you reported has been addressed in the R2020a release.”
But I did not find any related information in the online documentation for 2020a.
Given the date they notified me (long after R2020a release), I am guessing it means the issue is addressed in the upcoming R2020b release (expected September 2020). Hope to see the solution soon.
  1 comentario
Walter Roberson
Walter Roberson el 30 de Ag. de 2020
They actually do mean R2020a. But sometimes it can be pretty difficult to find the information. And sometimes their idea of what it means for an issue to have been addressed is very different from our ideas.
For example I made a recommendation that the special handling of sym('pi') as becoming the symbolic constant π be documented. They did address the issue... they disabled that behavior, and now sym('pi') just becomes an ordinary variable that happens to be named pi and you have to use sym(pi) to get the symbolic constant .
This offends my sensibilities, relying as it does on the fact that sym(pi) will go through a conversion routine that does a series of tests against known values to determine that 3.141592653589793115997963468544185161590576171875 (the exact value stored for the numeric function named pi) happens to be "close enough" to π to be rounded to π .
But, I gotta admit, they did address the issue...

Iniciar sesión para comentar.

Categorías

Más información sobre Develop uifigure-Based Apps en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by