Arrays have incompatible sizes for this operation.

14 次查看(过去 30 天)
y=4;
x=1;
k=y/x;
h=100;
Amax=10;
A=0:0.1:10;
a=2*x*pi*y.^-1;
i=0:h^-1:y;
B_i=floor(i+h^(-1));
f=48000;
F=f/k;
Eq=floor(A.*sin(a.*floor(B_i)+0.5))-A.*sin(a.*floor(B_i));
En=1/(12^(0.5));
Eqef=sqrt(sum(Eq.^2)./(h*y));
Kg=(Eqef.*100*sqrt(2))./A;
Kn=(En*100*sqrt(2))./A;
figure('Name','16','NumberTitle','off');
plot(A,Kg);
ylim([0,150]);
grid on;
hold on;
plot(A,Kn);
xlabel('A');
legend('Kg(A)','Kn(A)');
matlab gives an error:
Arrays have incompatible sizes for this operation.
Error in untitled2 (line 518)
Eq = floor (A. * sin (a. * Floor (B_i) +0.5)) - A. * sin (a. * Floor (B_i));
how to fix?
  2 个评论
H R
H R 2021-11-9
The size of A is 1 by 101 while the size of B_i is 1 by 401. You should change A to be the same size as B_i.

请先登录,再进行评论。

回答(1 个)

Sudharsana Iyengar
Sudharsana Iyengar 2021-11-9
Hi in your program you have A which is size 100 and B that is size 400. Thats is why this issue. Change your program to this.
y=4;
x=1;
k=y/x;
h=100;
Amax=10;
A=0:0.1:10;
a=2*x*pi*y.^-1;
i=0:h:y;% I removed h^-1 here.
B_i=floor(i+h^(-1));
f=48000;
F=f/k;
Eq=floor(A.*sin(a.*floor(B_i)+0.5))-A.*sin(a.*floor(B_i));
En=1/(12^(0.5));
Eqef=sqrt(sum(Eq.^2)./(h*y));
Kg=(Eqef.*100*sqrt(2))./A;
Kn=(En*100*sqrt(2))./A;
figure('Name','16','NumberTitle','off');
plot(A,Kg);
ylim([0,150]);
grid on;
hold on;
plot(A,Kn);
xlabel('A');
legend('Kg(A)','Kn(A)');

类别

Help CenterFile Exchange 中查找有关 Programming 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by