Matrix dimensions must agree.
1 次查看(过去 30 天)
显示 更早的评论
Hello all,
Not sure why this error "Matrix dimensions must agree." is popping up on line 37. I'm trying to simulate adding an electrode.
Matrix dimensions must agree.
Error in hodgkinhuxeqb (line 37)
Vm = V_in-V_out;
Here is my code:
function dSdt = hodgkinhuxeqb(T,S,I,Nd, D)
%Function hodgkinhuxeq
% Inputs: t - time
% I_add - input current
% v - voltage
%variables
V_in = S(1:6:end-5);
m = S(2:6:end-4);
h = S(3:6:end-3);
n = S(4:6:end-2);
s = S(5:6:end-1);
f = S(6:6:end);
%potentials
g_na = 120;
g_k = 36;
g_l = 0.3;
E_k = -77;
E_na = 50;
E_l = -54;
cm = 1;
tau_s = 6;
tau_f = 2;
esyn = 0;
gsyn = 0.01;
sigma = 0.00179;
V_out = I./(4.*pi().*sigma.*D);
V_out = transpose(V_out);
Vm = V_in-V_out;
% alpha and betas eqs
a_m = -0.1.*(Vm+35)./(exp(-0.1.*(Vm+35))-1);
b_m = 4.0.*exp((-Vm-60)./18);
a_h = 0.07.*exp(-0.05*(Vm+60));
b_h = 1./(1+exp(-0.1*(Vm+30)));
a_n = -0.01*(Vm+50)./(exp(-0.1*(Vm+50))-1);
b_n = 0.125*exp(-0.0125*(Vm+60));
%dv/dt sections
K_1 = (g_k.*n.^4.*(E_k-Vm));
Na_1 = (g_na.*m.^3.*h).*(E_na-Vm);
L_1 = g_l.*(E_l-Vm);
%Isyn = gsyn.*(s(end/3)-f(end/3)).*(esyn-v(end/3));
%derivats m,h,n,s
%dmdt = 0;
%dndt = 0;
%dhdt = 0;
dmdt = a_m.*(1-m)-b_m.*m;
dhdt = a_h.*(1-h)-b_h.*h;
dndt = a_n.*(1-n)-b_n.*n;
dfdt = -f/tau_f;
dsdt = -s/tau_s;
%dVdt = (1/cm).*((K_1)+(Na_1)+(L_1)+gsyn.*(s-f).*(esyn-v));
%membrane current for all the compartments
dVdt = 1./cm.*(g_l.*(E_l-Vm));
%na + k currents for all compartments
dVdt = dVdt + 1./cm.*(g_na.*m.^3.*h.*(E_na-Vm)+g_k.*n.^4.*(E_k-Vm));
% applied stimulus to the first compartment
%dVdt(1) = dVdt(1)+1./cm*Ielec;
%applied stim to middle of dendrite
%dVdt(end/2) = dVdt(end/2)+1./cm*Ielec;
R = 225;
a = 0.001;
dx = 0.001;
r = a/(2*R*dx^2);
% left and right sections
dVdt(2:end) = dVdt(2:end)+r.*(Vm(1:end-1)-Vm(2:end));
dVdt(1:end-1) = dVdt(1:end-1)+r.*(Vm(2:end)-Vm(1:end-1));
%merge output
dSdt = zeros(size(S));
dSdt(1:6:end-5) = dVdt;
dSdt(2:6:end-4) = dmdt;
dSdt(3:6:end-3) = dhdt;
dSdt(4:6:end-2) = dndt;
dSdt(5:6:end-1) = dsdt;
dSdt(6:6:end) = dfdt;
dSdt = [dVdt'; dmdt'; dhdt'; dndt'; dfdt'; dsdt'];
dSdt = dSdt(:);
end
2 个评论
Walter Roberson
2020-10-25
We do not know size(I) or size(D) so we cannot figure out size(v_out)
We do not know the orientation of S, so although if we guess that S is a vector, the length of v_in would be length(S)/6 but we do not know if v_in would be a row vector or column vector.
We do not know your MATLAB release, so we do not know if your MATLAB has implicit expansion or not (and we do not know if you intend implicit expansion to be deliberately used.)
Is there a reason why you do not reshape(S,6, []) and then extract rows of that, instead of using 2:6:end-4 and so on?
回答(1 个)
Srivardhan Gadila
2020-11-1
You can refer to Set Breakpoints & Debugging and Analysis to set breakpoint at line 37 and idenitfy the cause of the error.
While executing the code it appears that the size of V_in is 100x1 and that of V_out is 10x1, hence the error "Matrix dimensions must agree."
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Neural Simulation 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!