I created two arrays and a matrix and I'm trying to use the 'surf' function to plot but its erroring.

3 visualizzazioni (ultimi 30 giorni)
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)

Risposte (1)

Star Strider
Star Strider il 28 Ott 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)
X = 4×6
1 2 3 4 5 6 1 2 3 4 5 6 1 2 3 4 5 6 1 2 3 4 5 6
Y = 4×6
1 1 1 1 1 1 2 2 2 2 2 2 3 3 3 3 3 3 4 4 4 4 4 4
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)
1 2 3 4 5 6 2 3 4 5 6 7 3 4 5 6 7 8 4 5 6 7 8 9
%surf plot
subplot(2,2,1)
surf(X,Y,Z)
title('part3 surf','fontsize',20)
That appears to work.
.

Categorie

Scopri di più su Dates and Time in Help Center e File Exchange

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by