You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
Elliposid number of faces
1 view (last 30 days)
Show older comments
Hello can somebody help me to understand how i can change the number of faces of an ellipsoid with a slider in app designer
Answers (1)
Matt J
on 23 Jan 2022
Edited: Matt J
on 23 Jan 2022
You would just access the Value property of the slider in its callback. Then use that value to replot the ellipsoid.
10 Comments
HANZU OLIVIU-MIHAI
on 23 Jan 2022
Can you show me how ?
HANZU OLIVIU-MIHAI
on 23 Jan 2022
Edited: Matt J
on 23 Jan 2022
classdef app2 < matlab.apps.AppBase
% Properties that correspond to app components
properties (Access = public)
UIFigure matlab.ui.Figure
NSlider matlab.ui.control.Slider
NSliderLabel matlab.ui.control.Label
AparentaDropDown matlab.ui.control.DropDown
AparentaDropDownLabel matlab.ui.control.Label
DesenareStergereCheckBox matlab.ui.control.CheckBox
zrEditField matlab.ui.control.EditField
zrEditFieldLabel matlab.ui.control.Label
yrEditField matlab.ui.control.EditField
yrEditFieldLabel matlab.ui.control.Label
xrEditField matlab.ui.control.EditField
xrEditFieldLabel matlab.ui.control.Label
zcEditField matlab.ui.control.EditField
zcEditFieldLabel matlab.ui.control.Label
ycEditField matlab.ui.control.EditField
ycEditFieldLabel matlab.ui.control.Label
xcEditField matlab.ui.control.EditField
xcEditFieldLabel matlab.ui.control.Label
UIAxes matlab.ui.control.UIAxes
end
properties (Access = private)
xc = []; xr = [];
yc = []; yr = [];
zc = []; zr = [];
end
% Callbacks that handle component events
methods (Access = private)
% Value changed function: DesenareStergereCheckBox
function DesenareStergereCheckBoxValueChanged(app, event)
app.xc = app.xcEditField.Value;
app.yc = app.ycEditField.Value;
app.zc = app.zcEditField.Value;
app.xr = app.xrEditField.Value;
app.yr = app.yrEditField.Value;
app.zr = app.zrEditField.Value;
[X,Y,Z] = ellipsoid(str2num(app.xc),str2num(app.yc),str2num(app.zc),str2num(app.xr),str2num(app.yr),str2num(app.zr));
axis equal
if app.DesenareStergereCheckBox.Value
set(mesh(app.UIAxes,X,Y,Z),'visible','on')
else
set(mesh(app.UIAxes,X,Y,Z),'visible','off')
end
end
% Value changed function: AparentaDropDown
function AparentaDropDownValueChanged(app, event)
[X,Y,Z] = ellipsoid(str2num(app.xc),str2num(app.yc),str2num(app.zc),str2num(app.xr),str2num(app.yr),str2num(app.zr));
axis equal
switch app.AparentaDropDown.Value
case 'mesh'
(mesh(app.UIAxes,X,Y,Z));
case 'surf'
(surf(app.UIAxes,X,Y,Z));
case 'surface'
(surface(app.UIAxes,X,Y,Z));
case 'contour'
(contour(app.UIAxes,X,Y,Z));
end
end
% Value changed function: NSlider
function NSliderValueChanged(app, event)
value = app.NSlider.Value;
end
end
% Component initialization
methods (Access = private)
% Create UIFigure and components
function createComponents(app)
% Create UIFigure and hide until all components are created
app.UIFigure = uifigure('Visible', 'off');
app.UIFigure.Position = [100 100 804 517];
app.UIFigure.Name = 'MATLAB App';
% Create UIAxes
app.UIAxes = uiaxes(app.UIFigure);
title(app.UIAxes, 'Ellipsoid')
xlabel(app.UIAxes, 'X')
ylabel(app.UIAxes, 'Y')
zlabel(app.UIAxes, 'Z')
app.UIAxes.FontSize = 14;
app.UIAxes.Position = [41 149 410 284];
% Create xcEditFieldLabel
app.xcEditFieldLabel = uilabel(app.UIFigure);
app.xcEditFieldLabel.Position = [499 375 25 22];
app.xcEditFieldLabel.Text = 'xc';
% Create xcEditField
app.xcEditField = uieditfield(app.UIFigure, 'text');
app.xcEditField.Position = [539 375 70 22];
app.xcEditField.Value = '0';
% Create ycEditFieldLabel
app.ycEditFieldLabel = uilabel(app.UIFigure);
app.ycEditFieldLabel.Position = [499 323 25 22];
app.ycEditFieldLabel.Text = 'yc';
% Create ycEditField
app.ycEditField = uieditfield(app.UIFigure, 'text');
app.ycEditField.Position = [539 323 70 22];
app.ycEditField.Value = '0';
% Create zcEditFieldLabel
app.zcEditFieldLabel = uilabel(app.UIFigure);
app.zcEditFieldLabel.Position = [499 271 25 22];
app.zcEditFieldLabel.Text = 'zc';
% Create zcEditField
app.zcEditField = uieditfield(app.UIFigure, 'text');
app.zcEditField.Position = [539 271 70 22];
app.zcEditField.Value = '0';
% Create xrEditFieldLabel
app.xrEditFieldLabel = uilabel(app.UIFigure);
app.xrEditFieldLabel.Position = [649 375 25 22];
app.xrEditFieldLabel.Text = 'xr';
% Create xrEditField
app.xrEditField = uieditfield(app.UIFigure, 'text');
app.xrEditField.Position = [689 375 70 22];
app.xrEditField.Value = '0';
% Create yrEditFieldLabel
app.yrEditFieldLabel = uilabel(app.UIFigure);
app.yrEditFieldLabel.Position = [649 323 25 22];
app.yrEditFieldLabel.Text = 'yr';
% Create yrEditField
app.yrEditField = uieditfield(app.UIFigure, 'text');
app.yrEditField.Position = [689 323 70 22];
app.yrEditField.Value = '0';
% Create zrEditFieldLabel
app.zrEditFieldLabel = uilabel(app.UIFigure);
app.zrEditFieldLabel.Position = [649 270 25 22];
app.zrEditFieldLabel.Text = 'zr';
% Create zrEditField
app.zrEditField = uieditfield(app.UIFigure, 'text');
app.zrEditField.Position = [689 270 70 22];
app.zrEditField.Value = '0';
% Create DesenareStergereCheckBox
app.DesenareStergereCheckBox = uicheckbox(app.UIFigure);
app.DesenareStergereCheckBox.ValueChangedFcn = createCallbackFcn(app, @DesenareStergereCheckBoxValueChanged, true);
app.DesenareStergereCheckBox.Text = 'Desenare / Stergere';
app.DesenareStergereCheckBox.FontWeight = 'bold';
app.DesenareStergereCheckBox.FontColor = [0.149 0.149 0.149];
app.DesenareStergereCheckBox.Position = [499 161 135 33];
% Create AparentaDropDownLabel
app.AparentaDropDownLabel = uilabel(app.UIFigure);
app.AparentaDropDownLabel.HorizontalAlignment = 'right';
app.AparentaDropDownLabel.FontSize = 20;
app.AparentaDropDownLabel.FontWeight = 'bold';
app.AparentaDropDownLabel.FontColor = [0.149 0.149 0.149];
app.AparentaDropDownLabel.Position = [499 214 99 26];
app.AparentaDropDownLabel.Text = 'Aparenta:';
% Create AparentaDropDown
app.AparentaDropDown = uidropdown(app.UIFigure);
app.AparentaDropDown.Items = {'mesh', 'surf', 'surface', 'contour'};
app.AparentaDropDown.ValueChangedFcn = createCallbackFcn(app, @AparentaDropDownValueChanged, true);
app.AparentaDropDown.FontSize = 18;
app.AparentaDropDown.FontColor = [0.149 0.149 0.149];
app.AparentaDropDown.BackgroundColor = [0.9412 0.9412 0.9412];
app.AparentaDropDown.Position = [613 216 100 23];
app.AparentaDropDown.Value = 'mesh';
% Create NSliderLabel
app.NSliderLabel = uilabel(app.UIFigure);
app.NSliderLabel.Position = [530 128 14 22];
app.NSliderLabel.Text = 'N';
% Create NSlider
app.NSlider = uislider(app.UIFigure);
app.NSlider.Limits = [20 80];
app.NSlider.MajorTicks = [20 30 40 50 60 70 80];
app.NSlider.ValueChangedFcn = createCallbackFcn(app, @NSliderValueChanged, true);
app.NSlider.MinorTicks = [];
app.NSlider.Position = [556 137 194 3];
app.NSlider.Value = 20;
% Show the figure after all components are created
app.UIFigure.Visible = 'on';
end
end
% App creation and deletion
methods (Access = public)
% Construct app
function app = app2
% Create UIFigure and components
createComponents(app)
% Register the app with App Designer
registerApp(app, app.UIFigure)
if nargout == 0
clear app
end
end
% Code that executes before app deletion
function delete(app)
% Delete UIFigure when app is deleted
delete(app.UIFigure)
end
end
end
HANZU OLIVIU-MIHAI
on 23 Jan 2022
I get this error
HANZU OLIVIU-MIHAI
on 23 Jan 2022
% Value changed function: NSlider
function NSliderValueChanged(app, event)
N = app.NSlider.Value;
ellipsoid(app.xc,app.yc,app.zc,app.xr,app.yr,app.zr,app.N);
end
See Also
Categories
Find more on Develop uifigure-Based Apps in Help Center and File Exchange
Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)