How to change ax.View in app desginer?

11 次查看(过去 30 天)
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?

采纳的回答

Dominik Müller
Dominik Müller 2021-1-13
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 个评论
Cris LaPierre
Cris LaPierre 2021-1-13
编辑:Cris LaPierre 2021-1-13
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 2021-1-13
yep that is exactly what I meant by comparing a string ;-)

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Develop Apps Using App Designer 的更多信息

产品


版本

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by