RE-use helper function on multiple GUI components

1 visualización (últimos 30 días)
Ryan Martin
Ryan Martin el 4 de Ag. de 2020
Respondida: Cris LaPierre el 4 de Ag. de 2020
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;

Respuesta aceptada

Cris LaPierre
Cris LaPierre el 4 de Ag. de 2020
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.

Más respuestas (0)

Categorías

Más información sobre Develop Apps Using App Designer en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by