필터 지우기
필터 지우기

Error with the animation of the surface plot

조회 수: 4 (최근 30일)
Yuriy Yerin
Yuriy Yerin 2024년 5월 8일
댓글: Yuriy Yerin 2024년 5월 8일
Hello
I want to perform a surface animation, but I constantly run into an error
Error using surf
Data dimensions must agree.
Error in surfc (line 54)
hs = surf(cax, args{:});
Error in dcSQUID_diode_efficiency_animation (line 26)
surfc(phi,theta,eff)
I would be grateful if someone could tell me where exactly I made a mistake in the code
function z1=dcSQUID_diode_efficiency_animation
tic
phi0=linspace(0.000,2*pi,100);
theta0=linspace(0.000,2*pi,100);
flux1=linspace(0,1,10);
h = figure;
axis tight manual
filename = 'dc_squid_eff.gif';
for ii = 1:10
for i=1:100
for j=1:100
y=self11(phi0(i),theta0(j),flux1(ii));
eff(i,j,ii)=y;
end
end
[phi,theta]=meshgrid(phi0,theta0);
surfc(phi,theta,eff)
zlim([-0.5 0.5])
clim([-0.5 0.5])
colormap jet
colorbar('FontSize',34,'FontName','Times New Roman')
set(gca,'FontName','Times New Roman','FontSize',34)
xlabel('\phi','FontName','Times New Roman','fontsize',34,'fontweight','b');
ylabel('\theta','FontName','Times New Roman','fontsize',34,'fontweight','b');
set(gca,'XTick',0:pi/2:2*pi)
set(gca,'XTickLabel',{'0','\pi/2','\pi','3\pi/2','2\pi'})
set(gca,'YTick',0:pi/2:2*pi)
set(gca,'YTickLabel',{'0','\pi/2','\pi','3\pi/2','2\pi'})
drawnow
frame = getframe(h);
im = frame2im(frame);
[imind,cm] = rgb2ind(im,256);
if ii == 1
imwrite(imind,cm,filename,'gif', 'Loopcount',inf);
else
imwrite(imind,cm,filename,'gif','WriteMode','append');
end
end
function z2=self11(phi0,theta0,flux1)
rL1=1;
rL2=1;
rR0=1;
rR1=1;
rR2=1;
x = -2*pi:0.001:2*pi;
I_dc = cos(x./2).*atanh(sin(x./2))+rL1*cos((x+2*phi0)./2).*atanh(sin((x+2*phi0)./2))+rL2*cos((x+2*theta0)./2).*atanh(sin((x+2*theta0)./2))+...
rR0*cos((x-2*pi*flux1)./2).*atanh(sin((x-2*pi*flux1)./2))+rR1*cos(((x-2*pi*flux1)+2*phi0)./2).*atanh(sin(((x-2*pi*flux1)+2*phi0)./2))+...
rR2*cos(((x-2*pi*flux1)+2*theta0)./2).*atanh(sin(((x-2*pi*flux1)+2*theta0)./2));
I_min=min(I_dc);
I_max=max(I_dc);
z2=(I_max-abs(I_min))/(I_max+abs(I_min));
end
toc
end

채택된 답변

Venkat Siddarth Reddy
Venkat Siddarth Reddy 2024년 5월 8일
편집: Venkat Siddarth Reddy 2024년 5월 8일
Hi,
The problem you're encountering originates from the 26th line of your code, specifically:
surfc(phi,theta,eff);
This error arises because the variable "eff" you are passing to the surfc function is three-dimensional, whereas the other parameters, "phi" and "theta," are two-dimensional. The discrepancy in dimensions between the parameters is what triggers the error.
Interestingly, the first plot might have successfully generated because, during the initial iteration, the dimensions of eff were (100,100,1). With only one element in the third dimension, eff default to a 2D array. However, as iterations progress and the size of eff increases, it no longer defaults to a 2D array, hence the error in subsequent iterations.
To resolve this issue, you should explicitly specify which slice of the "eff" matrix you intend to plot by using indexing:
surfc(phi,theta, eff(:,:,ii)) %assuming you want to use iith array in iith iteration
To learn more about the surfc function,refer to the following documentation:
Hope it helps!
  댓글 수: 1
Yuriy Yerin
Yuriy Yerin 2024년 5월 8일
A lot of thanks for the prompt reply. Now it works perfect

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Tony
Tony 2024년 5월 8일
eff is three-dimensional, but the argument in surf must be two-dimensional. If you fix eff for a specific flux, that should work
surfc(phi,theta,eff(:,:,1))

Community Treasure Hunt

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

Start Hunting!

Translated by