How to change ax.View in app desginer?

9 vues (au cours des 30 derniers jours)
Dominik Müller
Dominik Müller le 13 Jan 2021
Commenté : Dominik Müller le 13 Jan 2021
Hi folks,
on my GUI im creating with App Designer I have an axes called app.UIAxes. And I have a drop down listing different viewing angles. What I want to do is the following:
By selecting a view I want to display on my axes, I enter a callback where I want to change app.UIAxes.View.
function changeView(app, event)
chosenView = app.DropDown.Value;
switch chosenView
case 1
view(app.UIAxes, [0 90]);
case 2
app.UIAxes.View = [30 30];
end
end
As you can see I tried two different ways to change the view of the axes but none of them is changing anything. after the callback the view stays the same as befor, no changes... Why? What am I doing wrong?

Réponse acceptée

Dominik Müller
Dominik Müller le 13 Jan 2021
Problem is solved:
If you enter items data it's stored as char. So therfor you have to cast from char to double or compare a string.
In my solution I cast a double out of char and then the switch-case works fine:
function changeView(app, event)
chosenView = str2double(app.DropDown.Value);
switch chosenView
case 1
view(app.UIAxes, [0 90]);
case 2
app.UIAxes.View = [30 30];
case 3
set(app.UIAxes, 'View', [90 0]);
end
end
All three cases can be used to change the view!
  2 commentaires
Cris LaPierre
Cris LaPierre le 13 Jan 2021
Modifié(e) : Cris LaPierre le 13 Jan 2021
The value of a dropdown is a character array.
The other option is to make your case expressions character arrays
chosenView = app.DropDown.Value;
switch chosenView
case '1'
view(app.UIAxes, [0 90]);
case '2'
app.UIAxes.View = [30 30];
case '3'
set(app.UIAxes, 'View', [90 0]);
end
Dominik Müller
Dominik Müller le 13 Jan 2021
yep that is exactly what I meant by comparing a string ;-)

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Develop Apps Using App Designer dans Help Center et File Exchange

Produits


Version

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by