Arrays have incompatible sizes for this operation.

17 ビュー (過去 30 日間)
david makarov
david makarov 2021 年 11 月 9 日
コメント済み: H R 2021 年 11 月 9 日
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.
H R
H R 2021 年 11 月 9 日
maybe A= linspace(0,10 , 401) ?

サインインしてコメントする。

回答 (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 Center および File ExchangeProgramming についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by