Getting following error while making Contourf plot [ Error using contourf Z must be at least a 2x2 matrix]

12 次查看(过去 30 天)
I am getting this error while making contour plot [ Error using contourf (Z must be at least a 2x2 matrix]. can someone please help how can i make an contour plot and also i wanted to add z data on it . I am basically looking for following contour plot. can someone please help how can i do it . Thanks in advance
clear all
close all
clc
[num,txt,raw] = xlsread('Book1.xlsx') ;
X = num(:,1) ;
Y = num(:,2) ;
Z = num(:,3) ;
figure(1)
contourf(X,Y,Z)

采纳的回答

KSSV
KSSV 2022-11-8
T = readtable('https://in.mathworks.com/matlabcentral/answers/uploaded_files/1185378/Book1.xlsx') ;
x = T.(1) ;
y = T.(2) ;
z = T.(3) ;
m = 50 ; n = 50 ;
xi = linspace(min(x),max(x),m) ;
yi = linspace(min(y),max(y),n) ;
[X,Y] = meshgrid(xi,yi) ;
Z = griddata(x,y,z,X,Y) ;
contourf(X,Y,Z)
  3 个评论
Prasad Joshi
Prasad Joshi 2022-11-9
Thank you sir for answer but But is it possible to get the full range of plot as shown in the below figure ..Thanks in advance
KSSV
KSSV 2022-11-9
You will get the data for the region which is covered by the scattered points. If you want it outisde you need to go for extrapolation; which is not suggested. However you can fix a constant value if you are aware of the data. Read the documentation part with extrapolation option.

请先登录,再进行评论。

更多回答(1 个)

KALYAN ACHARJYA
KALYAN ACHARJYA 2022-11-8
编辑:KALYAN ACHARJYA 2022-11-8
You may be look for other data visulization options, as its a 3 column data e.g
stem3, scatter3 or plot3
In mesh, surface, contour, Z much needed as as matrix (where respective valuses are assigned in grid plane)
  3 个评论
KALYAN ACHARJYA
KALYAN ACHARJYA 2022-11-8
Can you try using pen and paper to do data visualization in your case (3 column data)? Those surface plots need to have a grid plane/values.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Discrete Data Plots 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by