Arrays have incompatible sizes for this operation.

조회 수: 1 (최근 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 CenterFile Exchange에서 Operators and Elementary Operations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by