Index from Matching Element in Table
11 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Erika Hathaway
am 7 Aug. 2019
Kommentiert: Erika Hathaway
am 12 Aug. 2019
My overall goal is to replace data in a specific row by input data. (In App Designer, I have three input boxes [string, num, num], and when a button is pushed, I want this data to populate into an exisitng UITable.)
Currently, my table has Column A (Names), Column B (Start), and Column C (End). This is what I is happening/I want to happen:
- A user selects 'jumping' from Column A displayed in a ListBox. (This is working)
- User inputs NewName, NewStart, NewEnd. (Working) User presses okay.
- NewName should replace jumping, NewStart replace jumping start and NewEnd replace jumping end. (Not working)
My idea:
function OkayButtonPushed(app,event)
EditData(app);
end
function editdata(app)
%Find 'jumping' in Column A
%Index_Edit_Row = index of jumping
%[Index_Edit_Row, 2] = NewStart
%[Index_Edit_Row, 3] = NewEnd
end
Later, I want to be able to Delete the selected data row ('jumping' row), but I figure if I know how to edit it, it's a bit easier to delete.
I can't seem to find anything that will find a certain string in a column, then give me the index of it. I think strcmp will tell you if it matches or not, but that's not exactly what I want.
Thank you!
0 Kommentare
Akzeptierte Antwort
Adam Danz
am 7 Aug. 2019
% Get data from UITable
UIdata = app.UITable.Data;
% Find row of column 1 that matches "jumping"
% *note, strcmpi() is not case sensitive. If you want
% case sensitivity, use strcmp()
rowIdx = strcmpi(UIdata(:,1), 'jumping');
% Update columns 2 and 3 of the 'jumping' row
UIdata(rowIdx,[2,3]) = {999,9999};
% Load the updated data back into the UITable
app.UITable.Data = UIdata;
"Later, I want to be able to Delete the selected data row"
UIdata = app.UITable.Data;
rowIdx = strcmpi(UIdata(:,1), 'jumping');
UIdata(rowIdx,:) = []; % <---- delete row
app.UITable.Data = UIdata;
5 Kommentare
Adam Danz
am 8 Aug. 2019
This is hard to debug remotely. Could you put a break point at that line, execute the function, then save the following variables to a mat file and attach it?
- UIdata
- rowIdx
- app.NewName
- app.NewStart
- app.NewDuration
NewName = app.NewName;
NewStart = app.NewStart;
NewDuration = app.NewDuration;
save('debugData.mat', 'UIdata', 'rowIdx', 'NewName', 'NewStart', 'NewDuration')
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!