SyntaxError: Unexpected "for" in my matlab code

Good morning, I have an error message in my matlab code but I can't find where, it looks simple and all the variables are in their place I don't understand. Can you help me?
[m,i] = max(Natoms(4,:));
[m,j] = max(Natoms(4,:));
[m,k] = max(Natoms(4,:));
Natoms(4,:) = Natoms(4,:).*0;
Natoms(5,:) = Natoms(5,:).*0;
Natoms(6,:) = Natoms(6,:).*0;
d = [sqrt(D(1)*t) sqrt(D(2)*t) sqrt(D(3)*t);
m = [level(i) level(j) level(k)];
for kk = [1:Ni]
levelnb = [1];
if ion(kk,1) > 0
type = ion(kk,5);
xx = m(type) + erfinv(2*rand-1)*2*d(type);
ion(kk,1) = ion(kk,1) + xx;
x = ion(kk,1);
[levelnb] = new_level(x,levelnb,1,level,L,dx);
if levelnb(1) < L+1
Natoms(3+type,levelnb(1)) = Natoms(3+type,levelnb(1)) + 1;
end
end
end
File "diffusionf.m", line 52
for kk = [1:Ni]
^
SyntaxError: Unexpected "for"

 采纳的回答

On the line where you define the variable d you have an opening square bracket but no corresponding closing square bracket.

更多回答(0 个)

类别

帮助中心File Exchange 中查找有关 Entering Commands 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by