Error using contour (line 48) Z must be at least a 2x2 matrix.
조회 수: 2 (최근 30일)
이전 댓글 표시
Hello i hope im not missing something obvious by putting this here but ive been stuck for hours. I am trying to solve this problem, basically i need to fill a zero matrix with different values for von mises stress and then plot it using a contour plot. I continue to encounter the error in the title, i am also not sure if maybe the problem is in my loop rather than Z.
function Hertz2DContour (P,R,ECM,nu,mu,N)
% Hertz2DContour (P,R,ECM,nu,mu,N)
% Plots contours of von Mises equivalent stress
% P Load per unit length
% R Equivalent radius
% ECM Elastic contact modulus
% mu Friction coefficient
% N Number of points
% (1) Calculate and display semi-contact width, a
a = ((4*P*R)/(pi*ECM))^0.5
% (2) Calculate and display peak pressure, p0
p0 = (2*P/pi*a)
% Create vector of x values from -1.5a to 1.5a
X = linspace (-1.5*a,1.5*a,N);
% Create vector of z values fzom 0 to 3a
Z = ([1:N] - 0.5) * 3 * a / N;
% Create empty matrix for von Mises stress values
sv = zeros (N,N);
% (3) Loop through all X and Z values and calculate sv for each pair
for X=1:N
for Z=1:N
[sx,sz,tzx]=Hertz2DStress(P,R,ECM,nu,N)
sy=nu*(sx+sz);
I1=sx+sy+sz;
I2=sx*sy+sy*sz+sz*sx-(tzx^2);
I3=sx*sy*sz-(sy*tzx^2);
J2=I2-((I1^2)/3);
sv=sqrt(-3*J2);
end
end
% (4) Create a contour plot of the X,Z,sv
[X,Z]=meshgrid(X,Z)
contour(Z,sv,X)
Any help would be greatly appricated, thank you.
답변 (1개)
Star Strider
2020년 3월 24일
I have no idea what the arguments to your function are, so I cannot run your code.
Try this:
% Create empty matrix for von Mises stress values
sv = zeros (N,N);
% (3) Loop through all X and Z values and calculate sv for each pair
for X=1:N
for Z=1:N
[sx,sz,tzx]=Hertz2DStress(P,R,ECM,nu,N)
sy=nu*(sx+sz);
I1=sx+sy+sz;
I2=sx*sy+sy*sz+sz*sx-(tzx^2);
I3=sx*sy*sz-(sy*tzx^2);
J2=I2-((I1^2)/3);
sv(X,Z)=sqrt(-3*J2);
end
end
% (4) Create a contour plot of the X,Z,sv
[X,Z]=meshgrid(1:N)
contour(Z,sv,X)
I cannot test this. It should work, although ‘sv(Z,X)’ mighty be correct instead. Experiment!
댓글 수: 3
Star Strider
2020년 3월 24일
First, it does not appear that you have included the loop that I posted. That appears to create the matrix that contour requires.
Second, without the necessary arguments, I cannot test the code I post. If you provide them, I may be able to solve the problem.
Star Strider
2020년 3월 24일
Creating ‘sv’ as a matrix eliminiated the error that contour threw, however ‘sv’ is not changing. This is most readily apparent if you calculate:
cv_lims = min(sv(:))-max(sv(:))
producing:
cv_lims =
0
I am not certain what the problem is.
You will need to find that and fix it, since materials science is far from my areas of expertise.
참고 항목
카테고리
Help Center 및 File Exchange에서 Contour Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!