Arrays have incompatible sizes for this operation.

14 vues (au cours des 30 derniers jours)
david makarov
david makarov le 9 Nov 2021
Commenté : H R le 9 Nov 2021
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 commentaires
H R
H R le 9 Nov 2021
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 le 9 Nov 2021
maybe A= linspace(0,10 , 401) ?

Connectez-vous pour commenter.

Réponses (1)

Sudharsana Iyengar
Sudharsana Iyengar le 9 Nov 2021
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)');

Catégories

En savoir plus sur Programming dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by