wrote the code but the error says Unrecognized function or variable 'a'. Error in firle (line 13) Z = A(a)*B(b);

2 次查看(过去 30 天)
x= (0:.1:5);
y= (0:.1:5);
[X,Y] = meshgrid(x,y);
for n=1:7
for m=1:7
A = @(a) (2/sqrt(a))*sin((m*pi/5)*a);
B = @(b) sin((n*pi/5)*b);
Z = A(a)*B(b);
[X,Y,Z] = meshgrid(x,y,z);
surf(x,y,Z)
end
end

回答(2 个)

Cris LaPierre
Cris LaPierre 2020-7-30
The issue is with the line Z = A(a)*B(b);
You have not defined the variable 'a' or 'b'. That is resulting in the error you see. Did you mean to use n and m?

Image Analyst
Image Analyst 2020-7-31
Perhaps you wanted this:
x = 0 : 0.1 : 5;
y = 0 : 0.1 : 5;
[X, Y] = meshgrid(x, y);
a = X(:);
b = Y(:);
numElements = numel(a);
n = linspace(1, 7, numElements)';
m = n;
A = (2 ./ sqrt(a)) .* sin((m * pi/5) .* a);
B = sin((n * pi/5) .* b);
Z = A .* B;
% Reshape from column vector into 2-D
Z = reshape(Z, length(x), length(y));
surf(X, Y, Z)
xlabel('x', 'FontSize', 18);
ylabel('y', 'FontSize', 18);
zlabel('z', 'FontSize', 18);
Riddhi, is this what you wanted?

类别

Help CenterFile Exchange 中查找有关 Point Cloud Processing 的更多信息

产品


版本

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by