programmatical access to current selection in uitable under uifigure
조회 수: 38 (최근 30일)
이전 댓글 표시
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
댓글 수: 0
채택된 답변
Xiangrui Li
2020년 9월 20일
편집: Xiangrui Li
2020년 9월 20일
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.
추가 답변 (2개)
David Hill
2020년 6월 15일
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
Xiangrui Li
2020년 8월 29일
편집: Xiangrui Li
2020년 8월 29일
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.”
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
Walter Roberson
2020년 8월 30일
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...
참고 항목
카테고리
Help Center 및 File Exchange에서 Develop uifigure-Based Apps에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!