Issue with Plotting Data set based on Checkboxes in MATLAB App Designer
조회 수: 5 (최근 30일)
이전 댓글 표시
Hi,
I have an Excel file with data on a large number of devices. Each device has its own sheet within the Excel file.
I have a uitable with checkboxes setup in app designer so that when a check box is selected the data corresponding to that selection will be displayed on the plot. I need to be able to select more than one device at a time and all selected devices should appear on the plot.
When the user makes their selection by using the checkboxes in the uitable they then click a plot button, and their selected devices should be plotted. There is a clear button to clear the plot and the user should be able to repeat the process.
This is my code so far
%create the uitable, first column has the device names,
%second colunm has checkboxes
boxColumn = false(size(app.SheetName));
app.T = table(app.SheetName, boxColumn);
app.UITable.Data = app.T;
%callback to keep track of which checkboxes are selected
function UITableCellEdit(app, event)
indices = event.Indices;
newData = event.NewData;
if newData
app.SelectedDevices(end+1) = table2array(app.UITable.Data(indices(1),indices(2)-1));
else
app.SelectedDevices(ismember(app.SelectedDevices,app.UITable.Data(indices(1),indices(2)-1))) = [];
end
end
%selected devices plotted when button is pushed
function PlotButtonPushed(app, event)
probplot(app.UIAxes,app.Data(:,app.Data(app.SelectedDevices)));
legend(app.UIAxes,Sheetname,'-DynamicLegend','Location','best')
end
end
It is the last bit of code that I am having issues with. The error I'm getting is on the probplot line "Array indices must be positive integers or logical values."
I'd appreciate any help on this issue.
Andrew
댓글 수: 3
채택된 답변
Voss
2022년 6월 14일
I guess I would get the data to plot based on the selected checkboxes in app.UITable directly, without using app.SelectedDevices
probplot(app.UIAxes,app.Data(:,app.UITable.Data{:,2}));
and then, unless you need it for something else, you can do away with app.SelectedDevices (and therefore UITableCellEdit) entirely.
댓글 수: 8
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Develop Apps Using App Designer에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!