What is wrong with this matlab program?

1 view (last 30 days)
Nhl
Nhl on 17 Dec 2013
Answered: Paul on 18 Dec 2013
I have a homework question about a small-world network. My neuron model is FitzHugh Naguma (electrical coupling). I got this error ??? Error using ==> times Matrix dimensions must agree.
Error in ==> elec_syn_vr_swn at 42 I_syn = ( gsyn.* ( sum((Cshort).*con_mat,2).*x' - con_mat*x' ) )'; and small-world networks matlab codes are true or not? My program is:
%FHN Modeli_VR_Q_e_small-world_networks
clc;clf;clear;
deltat=0.01;
t=250;
j=0;
N=3;
con_mat=ones(N,N)-eye(N); %all-to-all network
for B=0.0:0.001:0.04
B
a=1.01;
j=j+1;
e=0.01;
A=0.01;
ohm=5;
w=0.1;
x=-0.8*ones(1,3);
y=-0.2*ones(1,3);
Isyn=zeros(1,3);
gsyn=0.1;
Qsin=0;
Qcos=0;
%SMALL_WORLD NETWORKS
n=50;%number of nodes
k=4;%the nearest neighbor
p=0.5;%coupling probability
r=zeros(1,n);r(2:k+1)=1;r(n-k+1:n)=1;
C=toeplitz(r)
%subplot(2,2,1), spy(C)
%subplot(2,2,2)
v=find(rand(n,1)< p);
Cshort=sparse(v,ceil(n*rand(size(v))),ones(size(v)),n,n)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%5
for i=1:t/deltat
x=x+deltat.*(x - x.^3/3 -y -Isyn)./e;
y=y+deltat.*(x +a +A.*cos(w*i*deltat) +B*cos(ohm*i*deltat) );
I_syn = ( gsyn.* ( sum((Cshort)'.*con_mat,2).*x' - con_mat*x' ) )';
Qv=x;
Qv(find(Qv<0))=-1;
Qvav=(1/N)*sum(Qv);
Qsin=Qsin+2*Qvav(2)*sin(w*i*deltat);
Qcos=Qcos+2*Qvav(2)*cos(w*i*deltat);
end
Qsin=Qsin/(t/deltat);
Qcos=Qcos/(t/deltat);
Qson(j)=sqrt(Qsin^2+Qcos^2);
end
Bplot=0.0:0.001:0.04;
plot(Bplot,Qson,'-o'),
grid on;
xlabel('B');
ylabel('Q');
  1 Comment
Walter Roberson
Walter Roberson on 17 Dec 2013
What difference do you observe between what you expect and what you get? Are you receiving an error message?

Sign in to comment.

Accepted Answer

Paul
Paul on 18 Dec 2013
The Line
sum((Cshort)'.*con_mat,2)
is what is causing your error.
Matlab uses matrix multiplication these matrices are not able to be multiplied together and so will cause an error.
Check your working to see if you have created these matrices correctly. What are they superposed to be ?

More Answers (0)

Categories

Find more on Graph and Network Algorithms in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!