plotting Graph in 3D help
0 Comments
Accepted Answer
12 Comments
Hi Fareeha,
To fix the error, ensure that the input matrix Z passed to the contourf function is at least a 2x2 matrix. Here's an example to demonstrate how to fix the error:
% Create sample data
x = 1:5; y = 1:5; [X, Y] = meshgrid(x, y);
% Example data, replace with your own data
Z = peaks(5);
% Plot the contour
contourf(X, Y, Z, 'LineWidth', 1.5);
Please see attached plot.
In this example, X and Y are 2D matrices created using meshgrid, and Z is a sample 5x5 matrix. By ensuring that Z is a valid 2D matrix, the error should be resolved when calling contourf.
Let me know if you need further assistance or help.
More Answers (1)
2 Comments
Hi Fareeha,
To modify the existing code to include streamlines, obtain the solution sol using bvp4c by extracting the velocity components u and v from sol.y to create a meshgrid for streamlines. Here is code snippet to show how to do it,
u = sol.y(3, :); % Extract u component
v = sol.y(2, :); % Extract v component
[X, Y] = meshgrid(x, y(1, :)); % Create meshgrid for streamlines
Next, plot the streamlines using the streamline function. Adjust the density of streamlines by specifying the starting points and the streamline spacing.
figure(2);
streamline(X, Y, reshape(u, size(X)), reshape(v, size(X)), [start_x1, start_x2, ...], [start_y1, start_y2, ...]);
xlabel('x', 'fontweight', 'bold', 'fontsize', 16);
ylabel('y', 'fontweight', 'bold', 'fontsize', 16);
title('Streamlines', 'fontweight', 'bold', 'fontsize', 16);
For more information on this function, please refer to
https://www.mathworks.com/help/matlab/ref/streamline.html
Make sure to replace [start_x1, start_x2, ...] and [start_y1, start_y2, ...] with the desired starting points for streamlines and specifying multiple starting points to visualize a variety of streamlines.
I hope this answers your question. Good luck!
See Also
Categories
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!