How do I implement surfc in app designer?

2 views (last 30 days)
Aji Bowo
Aji Bowo on 16 Nov 2022
Answered: Eric Delgado on 18 Nov 2022
I have a problem, in matlab i can code to graph 3D plot of complex function with surfc this is my code for that :
figure
X=-2*pi:0.2:2*pi;
Y=-2*pi:0.2:2*pi;
[x,y]=meshgrid(X,Y);
z=3*x+5i*y;
sc=surfc(x,y,abs(z))
xlabel('Re(x)');
ylabel('Im(y)');
colormap jet
colorbar
but here i want to implement this into app designer. I want user to input the complex function they have in cartesian with x and y (not polar), and then showing that plot to them. But when I run with the same code with a little bit of changes, I always get the error message : "Error using surfc. The surface Z must contain more than one row or column.". Here is my app designer callbacks :
% Button pushed function: MakeGraphButton
function MakeGraphButtonPushed(app, event)
x=-2*pi:0.2:2*pi;
y=-2*pi:0.2:2*pi;
[x,y]=meshgrid(x,y);
z=app.ComplexFunctionEditField.Value;
axes(app.UIAxes);
surfc(x,y,abs(z))
axis equal
grid on
end
end
How to make this works?

Answers (1)

Eric Delgado
Eric Delgado on 18 Nov 2022
Try this...
function ButtonPushed(app, event)
x=-2*pi:0.2:2*pi;
y=-2*pi:0.2:2*pi;
[x,y]=meshgrid(x,y);
z = str2func(app.EditField.Value);
surfc(app.UIAxes, x, y, abs(z(x,y)))
axis equal
grid on
end

Community Treasure Hunt

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

Start Hunting!