Info

Cette question est clôturée. Rouvrir pour modifier ou répondre.

How to fix Error using * Inner matrix dimensions must agree.? the error is in this line : Ptotal=(1/​(2*pi))*su​m(P(i)).*e​xp(1i*omeg​a*t);

1 vue (au cours des 30 derniers jours)
Florea George
Florea George le 8 Jan 2019
Clôturé : MATLAB Answer Bot le 20 Août 2021
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?

Réponses (1)

madhan ravi
madhan ravi le 8 Jan 2019
Modifié(e) : madhan ravi le 8 Jan 2019
P=P1.*P2; %remove the last loop
Ptotal=(1/(2*pi)).*sum(P).*exp(1i.*omega.*t);
  6 commentaires
Florea George
Florea George le 8 Jan 2019
Modifié(e) : Florea George le 8 Jan 2019
>> size(t)
size(P)
ans =
1 20001
Undefined function or variable 'P'.
>>
%Sorry. Its been a long day for me. thanks for helping me despite my lack of attention

Cette question est clôturée.

Community Treasure Hunt

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

Start Hunting!

Translated by