I created two arrays and a matrix and I'm trying to use the 'surf' function to plot but its erroring.
3 views (last 30 days)
Show older comments
this is the code I'm using and it is giving me this error: Error using surf (line 71)
Data dimensions must agree. I'm just not sure what this means or how to fix it.
Error in Lewis_Kailey_ComputerProject1_part3 (line 9)
surf(X,Y,Z)
x=[123456];
y=[1234];
[X,Y]=meshgrid(x,y);
Z = [1 2 3 4 5 6; 2 3 4 5 6 7; 3 4 5 6 7 8; 4 5 6 7 8 9];
disp(Z)
%surf plot
subplot(2,2,1)
surf(X,Y,Z)
title('part3 surf','fontsize',20)
0 Comments
Answers (1)
Star Strider
on 28 Oct 2021
Vectors need some sort of delimiters (spaces, commas, semicolons) to be defined correctly.
x=[123456]; % <— This Is The Problem
y=[1234]; % <— This Is The Problem
x=[1 2 3 4 5 6]; % <— This Is The Solution!
y=[1 2 3 4]; % <— This Is The Solution!
[X,Y]=meshgrid(x,y)
Z = [1 2 3 4 5 6; 2 3 4 5 6 7; 3 4 5 6 7 8; 4 5 6 7 8 9];
disp(Z)
%surf plot
subplot(2,2,1)
surf(X,Y,Z)
title('part3 surf','fontsize',20)
That appears to work.
.
0 Comments
See Also
Categories
Find more on Dates and Time in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!