Error using contourf Z must be at least a 2x2 matrix. Error in D18071 (line 106) contourf(st)

5 ビュー (過去 30 日間)
Hi, I am trying to create contour plot but after trying many times I am getting the same error, can anyone tell me what I am doing wrong in the code
*The code is*
s su = round(4*d/g)+1 ;
r = E((((su-1)- round(d/g)):-1:1),(su-1));
p = E((((su-1)- round(d/g)):-1:1),(su));
st = (p+r)./(1.5*(10)^(-4));
m = g*(size(r)-1);
H = 0:g:(m);
h = H./10;
writematrix(st)
type 'st.txt'
writematrix(h)
type 'h.txt'
plot(h,st)
xlim([0 1.5])
xlabel("X2/d",'fontsize',14)
ylabel("Normalised Strain along vertical path", 'fontsize',13)
legend("d/w = 0.5")
saveas(gcf,'plot.png')
contourf(st)
colorbar
saveas(gcf,'contour.png')

採用された回答

Sivsankar
Sivsankar 2024 年 7 月 18 日
編集済み: Sivsankar 2024 年 7 月 18 日
Hi Babar,
It seems that the error arises from the line
contourf(st)
The function expects you to send at least a 2x2 matrix as the argument. The error message suggests that Z is the argument, and it must be a function of two variables. In your case the argument is ‘st’.
From your code I can notice that the value of ‘st depends on ‘p’ and ‘r’ which in turn depend on the ‘E’ function. So, try to verify the value of ‘stbefore passing it to the ‘contourffunction and make sure it is a function of two variables, i.e, a 2x2 matrix or more.
You can also leverage the documentation on the ‘contourffunction:
Thanks.

その他の回答 (1 件)

Mohd Babar
Mohd Babar 2024 年 7 月 31 日
i have use the meshgrid function after defining the r and p, it helps to convert r and p vector to matrixs, but plot is not correct

カテゴリ

Help Center および File ExchangeContour Plots についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by