Error message when trying to plot 3D surface plot with colour bar
Show older comments
We are trying to create a surface plot to analyse the concentration of a advection diffusive equation. I'm experiencing two problems one is for my solver and the second is that my surf plot is coming up with an error. I think we've corrected the solver error but as we can't see the plot can't be sure if it's working. I've included the code that defines the mesh grid and matrix that is supposed to create the surface plot, the error message and all the values from the workspace in a picture. I'm n
%mesh grid/ line 18
x = 0:dx:Lx; %x nodes/ line 19
y = 0:dy:Ly; %y nodes/ line 20
t = 0:dt:T; %time intervals/ line 21
[X,Y] = meshgrid(x,y); % Create a meshgrid for X and Y/ line 23
% Initialize conditions and variables/line 25
Nx = length(x); %x nodes/line 26
Ny = length(y); %y nodes/line 27
Nt = length(t); %length of time intervals/ line 28
Cc = zeros(Nx, Ny, Nt); %line 29
Cc(:,:,1)=0; %line 30
for ik=1:length(C) %creating 3D matrix/ line 159
ix=floor(ik/Ny)+1;
iy=ik-(ix-1)*Ny;
if iy==0
iy=Ny;
ix=ix-1;
end
Cc(ix,iy,m+1)=C(ik);
end % line 167
Ccp = permute(Cc, [2, 1, 3]); % line 169
figure % Create a new figure
surf(X,Y,Ccp) % Create a surface plot (this is line 172)
% Enhance the plot with labels and colorbar
title('Concentration at Final Time Step');
xlabel('X');
ylabel('Y');
zlabel('Concentration');
colorbar; % Adds a colorbar to indicate the scale of concentration
view(2); %view from top
Error message:
Error using surf
Data dimensions must agree.
Error in Computing2024 (line 172)
surf(X,Y,Ccp) % Create a surface plot

Accepted Answer
More Answers (0)
Categories
Find more on Surface and Mesh Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
