Info
Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.
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 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (1)
madhan ravi
am 8 Jan. 2019
Bearbeitet: madhan ravi
am 8 Jan. 2019
P=P1.*P2; %remove the last loop
Ptotal=(1/(2*pi)).*sum(P).*exp(1i.*omega.*t);
6 Kommentare
Diese Frage ist geschlossen.
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!