1 view (last 30 days)

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

Srivardhan Gadila
on 1 Nov 2020

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."

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

Start Hunting!
## 2 Comments

## Direct link to this comment

https://in.mathworks.com/matlabcentral/answers/625878-matrix-dimensions-must-agree#comment_1085838

⋮## Direct link to this comment

https://in.mathworks.com/matlabcentral/answers/625878-matrix-dimensions-must-agree#comment_1085838

## Direct link to this comment

https://in.mathworks.com/matlabcentral/answers/625878-matrix-dimensions-must-agree#comment_1085868

⋮## Direct link to this comment

https://in.mathworks.com/matlabcentral/answers/625878-matrix-dimensions-must-agree#comment_1085868

Sign in to comment.