Error in using contourf

1 次查看(过去 30 天)
Shafiqah Alya
Shafiqah Alya 2021-1-1
I got error while running this code which is the error of countourf. How to fix this?
clear, all clc;
x = linspace(-1,1);% create linear spacing in x-direction
y = linspace(-1,1);% create linear spacing in y-direction
%initialise velocity
U = 1;%freestream velocity
%looping in i and j-directions
for i = 1:length(x)
for j = 1:length(y)
%create x & y space
xx(i,j) = x(i);
yy(i,j) = y(j);
%calculate radius from x & y
rad(i,j) = sqrt(x(i)^2 + y(j)^2);
% calculate angle from x and y
if x(i) > 0
theta(i,j) = atan(y(j)/x(i));
elseif x(i) <0 && y(j) >= 0
theta(i,j) =atan(y(j)/x(i))+pi;
elseif x(i) < 0 && y(j) < 0
theta(i,j) = atan(y(j)/x(i))-pi;
elseif x(i) == 0 && y(j) < 0
theta(i,j) = pi/2;
else
theta(i,j) = -pi/2;
end
% calculate stream function using polar coordinate system
psi(i,j) = U *rad(i,j)*sin(theta(i,j));
% calculate velocity potential using polar coordinate system
phi(i,j) = U*rad(i,j)*cos(theta(i,j));
end
end
%plotting
contourf(xx,yy,psi,-1:0.2:1,'k','LineWidth',1.5), hold on�% plot stream function for range -1:0.1:1
contour(xx,yy,phi,-1:0.2:1,'r','LineWidth',1.5)% plot velocity potential for range -1:0.2:1
axis image, hold off
legend('streamlines','potential')
title('Uniform stream in x-direction')
xlabel('x-coordinate'), ylabel('y-coordinate')
axis square;
% end of Octave program

回答(1 个)

Star Strider
Star Strider 2021-1-1
There is an invalid text character:
contourf(xx,yy,psi,-1:0.2:1,'k','LineWidth',1.5), hold on�% plot stream function for range -1:0.1:1
↑ ← HERE
If that is corrected (eliminated), your code appears to work (in MATLAB R2020b Update 3).
.

类别

Help CenterFile Exchange 中查找有关 Get Started with Image Processing Toolbox 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by