Unable to perform assignment because the indices on the left side are not compatible with the size of the right side.

조회 수: 2 (최근 30일)
My code doesn't work, it gives me an error:
"Unable to perform assignment because the indices on the left side are not compatible with the size of the right side."
But before that, my code worked well until I made corrections to the functions: function p1 = f_p1(n,t) and function p2 = f_p2(n,t);
I added a multiplier: (1 + 1./(pi*Kb*1.2.*(n+1).*0.1*2))
Why did such a problem arise, how can it be fixed?
My code:
%% initial conditions
% global k0 h_bar ksi m E C_2
global tau T
Ef = 2.77*10^3;
tau = 0.2; % TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT
v_f = 1;
l_pr = 1;
T = 1.2; %kelvin
% tau = l_pr/v_f;
Kb = physconst('boltzmann'); % 1.38*10^(-23)
m = 9.1093837*10^(-31);
Tc = 1.2;
ksi = 10^(-9);
h_bar = (1.0545726*10^(-34));
k0 = (ksi/h_bar)*sqrt(2.*m.*pi.*Kb.*Tc);
C_2 = 6.81;
t = linspace(0.1, 2,500);
D = linspace(2*10^(-9), 70*10^(-9),500);
d = D./ksi;
for i=1:numel(d)
for j = 1:numel(t)
F(i,j) = f_calc(t(j),d(i), k0, h_bar, ksi, m, C_2);
end
end
%plot(t,F)
figure
[c,h] = contour(t,d,F,[0 0]);
xlabel('d')
ylabel('t')
% tv = c(2, 2:end);
% dv = c(1, 2:end);
[tv,dv] = getContour0(c,h);
Q1 = [size(c); size(tv)]
figure
plot(dv, tv)
xlabel('d')
ylabel('t')
grid
function F = f_calc(t, d, k0, h_bar, ksi, m, C_2)
nD = floor(375/(2*pi.*t*1.2) - 0.5);
F = 0;
for k = 0:nD
F = F + 1/(2*k+1).*imag(f_lg(k,t,d,k0)+1i.*d.*k0.*((f_p1(k,t)-f_p2(k,t))./2)+1i*f_arg_1(k,t,d,k0)-1i*f_arg_2(k,t,d,k0));
end
F = -(1/d).*F - 7.826922968141167;
end
function p1 = f_p1(n,t) % new
global Kb
p1 = ((1+1i)./sqrt(2)).*sqrt(t.*(2.*n+1).*(1 + 1./(pi*Kb*1.2.*(n+1).*0.1*2)));
end
function p2 = f_p2(n,t) % new
global Kb
p2 = sqrt(3601+1i.*t.*(2.*n+1).*(1 + 1./(pi*Kb*1.2.*(n+1).*0.1*2)));
end
function arg_1 = f_arg_1(n,t,d,k0)
arg_1 = angle(1+exp(-1i.*d*k0.*f_p1(n,t)));
end
function arg_2 = f_arg_2(n,t,d,k0)
arg_2 = angle(1+exp(-1i.*d*k0.*f_p2(n,t)));
end
function n_lg = f_lg(n,t,d,k0)
arg_of_lg = (1+exp(-1i.*d.*k0.*f_p1(n,t)))/(1+exp(-1i.*d.*k0.*f_p2(n,t)));
n_lg = log(abs(arg_of_lg));
end
function [xv,yv] = getContour0(M,C)
Levels = C.LevelList
for k = 1:numel(Levels)
idx = find(M(1,:) == 0);
ValidV = rem(M(2,idx),1) == 0;
StartIdx{k,:} = idx(ValidV);
VLen{k,:} = M(2,StartIdx{k});
% Q3 = numel(StartIdx{k})
for k1 = 1:numel(StartIdx{k})
% Q4 = StartIdx{k}(k1)
idxv = StartIdx{k}(k1)+1 : StartIdx{k}(k1)+VLen{k}(k1);
xc{k1} = M(1,idxv);
yc{k1} = M(2,idxv);
end
end
xy = [cell2mat(xc); cell2mat(yc)].';
xy = sortrows(xy,2);
xv = xy(:,1).';
yv = xy(:,2).';
end

답변 (1개)

Torsten
Torsten 2023년 3월 10일
You don't define Kb as a global variable in the part of your code where you set it as
Kb = physconst('boltzmann'); % 1.38*10^(-23)
  댓글 수: 2
Dmitry
Dmitry 2023년 3월 10일
Torsten, If I put instead Kb just a number 1.38*10^(-23) will the code work correctly?
Torsten
Torsten 2023년 3월 10일
It works if you replace the first line of your code by
global tau T Kb
If it gives reasonable results: I don't know.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Applications에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by