I have a uitable with 10 columns, which I'm populating from a db.
Now I want to know when the user choose a specific row. For example if the user chooses the 3rd record, I would like to get back the value 3, so then I could access the actual information to for example open that specific record from the path.
I found online that I would need findjobj.
I also think that the method should be implemented in here:
function uitable_CellSelectionCallback(hObject, eventdata, handles)
However I found a little information about how I should proceed.
Anyone had this problem or knows how to solve it?
When calling the CellSelectionCallback you can access the Indices property, which is a 2 x 1 array containing the row and column indices of the cell you have selected.
Therefore in your callback, use something like this:
row = eventdata.Indices(1)
col = eventdata.Indices(2)
and that should get you going.
In order to avoid callbacks, you can use app.UITable.Selection in the newer versions of MATLAB where app is your app object and UITable your uitable name
Related
I am building an application in MATLAB app designer (2019b), and I am trying to link two blank fields to a table that has only two columns, such that the first field should show the first value (in the first column) in the table and the other should show the last value in the first column in the table.
Example
table:
9 2
3 4
5 6
blank field_1: 9
blank field_2: 5
I am a C++ person, so whenever I am developing, for instance in SFML, I just have one event loop that captures and updates everything - no matter where I press on the window, but, in MATLAB, whenever I press a button - I need to build a separate callback function. Here, I am not calling back anything - I just need to update the value.
Anyone, please help?
Thank you
Here's an example which illustrates how you can achieve the behavior you want.
In the below example, I am creating a uitable in the App startup, and I am defining a callback which updates the table as required when the cells are modified.
function startupFcn(app)
vars = {9,2;3,4;5,6;'blank _field_1:', '';'blank field_2:', ''};
t = uitable(app.UIFigure,'Data',vars);
t.ColumnEditable = true;
t.DisplayDataChangedFcn = #updateTable;
function updateTable(src,~)
src.Data(end-1:end,2:end) = [src.Data(1,1) src.Data(end-2,1)].';
end
end
I'm currently working on a GUI that has a uitable within it. The idea is to allow the user to input a string and press a button to add a new row of cells, like so: ui_table_currently.
In addition to this, when the user clicks 'accept', the data set so far would be saved. This means if the user were to load up the GUI again, the same data set would be shown as when they closed down the GUI.
In practice, I've managed to save the data set with the users input into the workspace in MATLAB, however, I cannot update the data set that is shown in the uitable when I reload the GUI, unless I use GUIDE and change uitable via (Inspector > Table Property Editor > Data > Change data value to the selected workspace variable).
My question is this: How do I get uitable to retain the data set it has when I close it, without manually having to change it through GUIDE?
You should have two files created with GUIDE. For the sake of example, let's say your's are named raimo.fig and raimo.m. Let's also say you gave your uitable the tag, 'table_1'.
If you edit the raimo.m file, you should see a line like this
% --- Executes just before analysis is made visible.
function raimo_OpeningFcn(hObject, eventdata, handles, varargin)`
Load your data from the file within this function, and then give it to your user data.
Here's a made up example of how to do it:
a = load('yourAmbiguousData');
set(handles.table_1,'table',a);
I don't know how your data is saved, or what is called, but if you have pulled it out of your uitable correctly, you can just put it back in there with a set command.
I'm currently facing the following problem:
In my abap program I am using an ALV grid to display a list of data.
Now I have got the requirement to convert the data of cell 5 depending on the value entered in cell 3. Normally I could just do this by implementing a handler method for the DataChanged or DataChangedFinished events.
But in my case the value of cell 3 is written into the backend table i connected to the alv grid when creating it via the method SET_TABLE_FOR_FIRST_DISPLAY. That means the alv does not register it when the data is changed. I also tried to use the method CHANGE_DATA_FROM_INSIDE of CL_GUI_ALV_GRID and this partly works if I set the value of VAL_DATA in the layout structure to 'X' when initializing the grid. The program runs through my handler for the DataChanged event.
But in my case it results in a short dump because the method can only work with caracter fields and I need cell 3 and cell 5 to be decimals. The dump is caused in the GET_CHANGED_DATA method of CL_GUI_ALV_GRID. When I am applying this mechanism to character fields it works fine.
This question refers to the following thread where I got the idea of setting the VAL_DATA flag of the layout structure from:
StackOverFlow Question
Did anyone ever face the same problem? Do you have any advice for me?
I am creating a uitable using GUIDE with 4 columns: 1st – Numeric, 2nd – Let Matlab choose,
3rd – Text, Editable, 4th – Logical, Editable.
When I run my GUI and try to mark the Logical checkbox I get this error: Warning: Table data is not editable at this location. Please click for more information.
I have tried to solve the problem and failed. Therefore, how can I fix it? I wish to check or uncheck them (the default selection should be checked).
Thanks.
Try this in the create function for your uitable:
set(yourUitableHandle, 'ColumnEditable', [0 1 1 1]);
If the problem persists, something in GUIDE is automatically changing that property for you. Likely on the Data section of property viewer for the uitable. Let me know if that doesn't fix it, and I'll give it another shot.
Currently I have a GUI in which once a 'Submit' button is pressed the drop menu which is left blank is then populated by a calculated value determined by the three other values.
I have successfully figured out how to grab all of the values using this logic:
temp=get(handles.FSTOPpopmenu,{'String','Value'});
fstop=temp{1}{temp{2}};
if (strcmp(fstop,'Select'))
fstop = 0;
else
fstop = str2num(fstop);
end
I just have two questions about this that I can not seem to find an answer for.
How would I go about updating the 'empty' drop menu to the calculated variable (the calculated variable will already be one of the possible values in the predetermined list)?
How would I go about presenting an error, say if I have an if statement checking that the amount of zeros in the array? Would a pop up box be sufficient?
Cheers.
As for your first question matlab's set command is what you're looking for. The documentation is here. You would probably need:
MyValueIndex = find(DropDownValues==NewValue);
switch handleToChange
case handles.handle1
set(handles.handle1,'Value',MyValueIndex);
case handles.handle2
set(handles.handle2,'Value',MyValueIndex);
otherwise
error('Uh oh!');
end
Note that MyValueIndex is the index of dropdown box values that you want. Which is found with a find command on the actual value.
Question two is more of an opinion question but I think that a pop-up box describing the problem is sufficient. Maybe add in a system beep for good measure!
Reference:
http://www.mathworks.com/matlabcentral/answers/22734-resetting-a-pop-up-menu-in-a-gui
http://www.mathworks.com/help/matlab/ref/find.html
http://www.mathworks.com/help/matlab/ref/switch.html
For a popupmenu uicontrol the Value property determines which element of the String property is currently being displayed. Get the String; compare its contents to the calculated variable to get the index; then set that index as the Value property. If the calculated variable is not currently in the String then add it to the String and then set the Value. (Note when comparing you need to compare numbers to numbers or string to strings, so you may need to do an appropriate data type conversion first).
Use an errordlg.