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

3 ビュー (過去 30 日間)
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)

回答 (1 件)

Star Strider
Star Strider 2021 年 10 月 28 日
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.
.

カテゴリ

Help Center および File ExchangeDates and Time についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by