Info

この質問は閉じられています。 編集または回答するには再度開いてください。

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);

2 ビュー (過去 30 日間)
Florea George
Florea George 2019 年 1 月 8 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
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?

回答 (1 件)

madhan ravi
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 件のコメント
Florea George
Florea George 2019 年 1 月 8 日
編集済み: Florea George 2019 年 1 月 8 日
>> 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

この質問は閉じられています。

Community Treasure Hunt

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

Start Hunting!

Translated by