How do I implement surfc in app designer?

조회 수: 3 (최근 30일)
Aji Bowo
Aji Bowo 2022년 11월 16일
답변: Eric Delgado 2022년 11월 18일
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?

답변 (1개)

Eric Delgado
Eric Delgado 2022년 11월 18일
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

카테고리

Help CenterFile Exchange에서 Annotations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by