RE-use helper function on multiple GUI components

1 次查看(过去 30 天)
I am working on an app that displays information about an image that has been loaded. The user imports an image and it is displayed on an axes component. From there, the user selects 4 ROIs and the app displays some properties of each ROI (pixel count, average value, min and max, std dev) in a panel. Rather than write 4 separate functions for displaying all the information, is there a way I can re-use one function to update each panel? Right now I am looking at replicating this 4 times (r1, r2, r3, and r4):
app.r1PixelsEditField.Value = region.pixel_count;
app.r1AvgCountsEditField.Value = region.count_average;
app.r1MinCountEditField.Value = region.count_min;
app.r1MaxCountEditField.Value = region.count_max;
app.r1StdDevEditField.Value = region.std_dev;

采纳的回答

Cris LaPierre
Cris LaPierre 2020-8-4
Since the app structure is a structure, you can dynamically set the field names. There are a couple ways you could do it. Here's a simple example I mocked up using your component names.
% Private function created in app designer
function updateEdits(app,r)
app.(r+"PixelsEditField").Value = 3;
app.(r+"AvgCountsEditField").Value = 5;
app.(r+"MinCountEditField").Value = 10;
app.(r+"MaxCountEditField").Value = 15;
app.(r+"StdDevEditField").Value = 200;
end
I then had a button that, when pressed, would update the values of these 5 edit fields for r1, r2 and r3.
% Button pushed function: Button
function ButtonPushed(app, event)
updateEdits(app,"r1");
updateEdits(app,"r2");
updateEdits(app,"r3");
end
Here's what it looked like.

更多回答(0 个)

类别

Help CenterFile 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!

Translated by