Info

This question is closed. Reopen it to edit or answer.

How I can create a for loop where i store a matrix for each index value

1 view (last 30 days)
Hi, I have a problem in my code, I am beginner and I am totally stuck. I have a project where n is a number of cells (1 to 25) and I want to create a structure (I use struct) where I store 5 parameters for each cells. The next step is to add in this structure a new parameters ( a matrix call K) where I find in the first colunm the neighbors cells called m (so i put a second loop (the cell that are closer enought we compute the distance) and then compute the area in common (call w). But there are many problem in my code I think because my loop doesn't work for store all the K(n). I put my code if someone can help me with this it will be very nice=)
for t= [1:240:0.25] for n=1:Nc S(n,t)=struct(field1,value1,field2,value2,field3,value3,field4,value4,field5,value5,field6,value6); end end
%%%%%%%QUESTION 3%%%%%%%%
r=8.5%radius of cells
for n=1:Nc k=1; %n=int8(n); %K(n)=getdata(n); K=zeros(k,2);
for m=1:Nc
d2=(x(n)-x(m))^2+(y(n)-y(m))^2;%distance entre 2 cellules pour voir si elles sont suffisamment proche
d=sqrt(d2);
if d<=2*r
Atot=pi*r^2;
teta=2*acos(d/(2*r));
H=2*sin(teta/2)*r;
Ao(n,m)=teta*r^2-H*d;
w(n)=Ao(n,m)/Atot;
if w(n)>0
%K(k,1)=m;
%K(k, 2)=w(n);
K(k,:)=[m w(n)];
k=k+1;
end
end
S(n,t).field6 =K(n);
end
end

Answers (0)

Community Treasure Hunt

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

Start Hunting!