Matrix dimensions must agree in a function with the sum
조회 수: 1 (최근 30일)
이전 댓글 표시
Hello everybody.
Sorry for a stupid question but can't resolve this problem.
How can I avoid the error "Matrix dimensions must agree" without implementation of two loops for two variables?
The code is below.
function z=coeff
n=0:1:100000;
t=linspace(0.5,1.25,100);
G=linspace(0.1,1,100);
[t G] = meshgrid(t,G);
b11= @(t, G) (pi*t.*(sum((((2*n+1).*pi.*t)+G).^4./(((2*n+1).*pi.*t).^3.*(((2*n+1).*pi.*t)+2*G).^4)))+...
pi*t*(sum((((2*n+1).*pi.*t)+G).*G.*(G.^2+3*G.*((2*n+1).*pi.*t)+((2*n+1).*pi.*t).^2)./(((2*n+1).*pi.*t).^3.*(((2*n+1).*pi.*t)+2*G).^4))));
z1=b11(t,G);
contourf(t,G,z1);
colormap jet
colorbar
set(gca,'FontName','Times New Roman','FontSize',34)
end
Many thanks in advance.
댓글 수: 1
Torsten
2022년 1월 18일
Insert the lines
size(t)
size(G)
size(n)
after the call to meshgrid.
These sizes must be equal in order for the function b11 to work. In your case, they are different.
답변 (0개)
참고 항목
카테고리
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!