Info
이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.
How to fix Error using * Inner matrix dimensions must agree.? the error is in this line : Ptotal=(1/(2*pi))*sum(P(i)).*exp(1i*omega*t);
조회 수: 1 (최근 30일)
이전 댓글 표시
pas = 1/1000;
t=-10:pas:10;
t0 = 0; %deplasarea por?ii
A = 1;
p1= poarta(-A/2,A/2,1,t-t0);
p2=poarta(-A/2,A/2,1,t-t0);
figure(1);
subplot(2,1,1);
plot(t,p1), title('Poarta 1');
subplot(2,1,2);
plot(t,p2), title('Poarta 2');
k=10;
omega = -k*pi/A:1/10:k*pi/A;
P1 = zeros(1,length(omega));
for i=1:length(omega)
P1(i) = integral(@(t)poarta(-A/2,A/2,1,t-t0).*exp(-1i*omega(i)*t),-100,100);
re = real(P1(i));
im = imag(P1(i));
if abs(re)<10^-10
re = 0;
end
if abs(im)<10^-10
im = 0;
end
P1(i) = re+1i*im;
end
figure(2);
subplot(2,1,1);
plot(omega,abs(P1)), title('Parte reala P1');
subplot(2,1,2);
plot(omega,angle(P1)), title('Parte imaginara P1');
figure(3);
plot3(omega,real(P1),imag(P1));
title('Poarta 1');
xlabel('Frecventa unghiulara');
ylabel('Partea reala');
zlabel('Partea imaginara');
P2 = zeros(1,length(omega));
for i=1:length(omega)
P2(i) = integral(@(t)poarta(-A/2,A/2,1,t-t0).*exp(-1i*omega(i)*t),-100,100);
re = real(P2(i));
im = imag(P2(i));
if abs(re)<10^-10
re = 0;
end
if abs(im)<10^-10
im = 0;
end
P2(i) = re+1i*im;
end
figure(4);
subplot(2,1,1);
plot(omega,abs(P2)), title('Parte reala P2');
subplot(2,1,2);
plot(omega,angle(P2)), title('Parte imaginara P2');
figure(5);
plot3(omega,real(P2),imag(P2));
title('Poarta 2');
xlabel('Frecventa unghiulara');
ylabel('Partea reala');
zlabel('Partea imaginara');
for i=1:length(omega)
P(i)=P1(i)*P2(i);
end
Ptotal=(1/(2*pi))*sum(P(i)).*exp(1i*omega*t);
%The problem seems to be on the last row. Error using * Inner matrix dimensions must agree.
%I've tryed to put .* everywhere * is, but the error persists. How can i fix it?
댓글 수: 0
답변 (1개)
madhan ravi
2019년 1월 8일
편집: madhan ravi
2019년 1월 8일
P=P1.*P2; %remove the last loop
Ptotal=(1/(2*pi)).*sum(P).*exp(1i.*omega.*t);
댓글 수: 6
이 질문은 마감되었습니다.
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!