Index from Matching Element in Table
11 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Adam Danz
2019-8-7
% 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 个评论
Adam Danz
2019-8-8
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')
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!