How to do the check box in GUI app designer ??

19 visualizaciones (últimos 30 días)
Rami
Rami el 4 de Dic. de 2021
Editada: Dave B el 4 de Dic. de 2021
when I check on the box I got the wanted results , hovever, when I remove the check I get an error message rather than the original shape.
value = app.DegreeCheckBox.Value;
global roi;
x = roi.Position;
x_val = x(:,1);
y_val = x(:,2);
polygon = polyshape(x_val, y_val);
if app.DegreeCheckBox.Value == 1
pg = plot(app.UIAxes, polygon, 'FaceColor', '#4DBEEE', 'FaceAlpha', 0.8);
hold (app.UIAxes, 'on');
poly3 = rotate(polygon, 45);
ps = plot(app.UIAxes, poly3, 'FaceColor','#FF00FF','FaceAlpha', 0.8 );
axis (app.UIAxes, 'tight', 'equal');
  2 comentarios
Dave B
Dave B el 4 de Dic. de 2021
Editada: Dave B el 4 de Dic. de 2021
Is it the same error as you described in your post about radio buttons? If so then I don't think this is about the check boxes. Does the error occur on the x = roi.Position line? Could it be that roi has been deleted? You haven't given much information on where roi came from...My instinct is if there's a global variable and a bug there's a decent chance that they are related...
Maybe roi was an object in the axes and when you called plot (with the hold state off from the previous round) you blew it away?
Rami
Rami el 4 de Dic. de 2021
Yeah I got error on the line x = roi.Position , roi = drawpolygon(app.UIAxes) . so , how can I fix it from beeing deleted . Should I not use "global".

Iniciar sesión para comentar.

Respuesta aceptada

Dave B
Dave B el 4 de Dic. de 2021
You should not use global, roi should probably be a property on your app.
But I think to prevent it from being deleted, you need to alter your plot code...I suspect that calling hold on and hold off is the issue here: when hold is off the first plot command replaces everything in your axes including the rois. So I think you need a strategy that says 'keep the rois' and 'delete the Polygons'
There are a few options here, I think my strategy would probably be to:
  • leave hold on throughout the app, so you're always adding to the axes.
  • Store the Polygon objects that you're plotting in properties too: define properties that correspond to pg and ps here, and then capture those when you call plot.
  • Instead of relying on the hold off, manually delete the Polygon objects when you enter your callback.
  2 comentarios
Rami
Rami el 4 de Dic. de 2021
Thank u for your help , as I'm a begineer in matlab it will be so helpful if you can show me on how to code it .
Dave B
Dave B el 4 de Dic. de 2021
It's a bit tricky with app designer to 'show you how'
Defining a property looks like:
properties
myprop
end
deleting an object looks like:
delete(app.myprop)
sotring the polygons will look like:
app.myprop = plot(...)

Iniciar sesión para comentar.

Más respuestas (0)

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by