argchina
2009-05-17, 22:43
我是初学者,有一个问题想请教大家。
在循环嵌套中的内循环的的for 语句中能不能包含父循环for 语句中的循环指数?
例子:
clear all;
x = input('entrer un chiffre entier impair : ');
if mod(x,2)==0
fprintf('%.0f n''est pas un chiffre entier impair \n',x);
else
str_space='';
for k=1:(x+1)/2
for n=1:1:(x-(2k-1)/2)/2
str_space=strcat(str_space,' ');
end
for n=1:(2k-1)
str_etoile=strcat(str_etoile,'*');
end
str_result=[str_space str_etoile str_space];
fprintf('%s \n',str_result);
end
end
系统说“for n=1:1:(x-(2k-1)/2)/2 ”有错误“Unexpected MATLAB expression.”。我不知道那里出错了,那一位朋友帮我找出为什么出错?谢谢!
在循环嵌套中的内循环的的for 语句中能不能包含父循环for 语句中的循环指数?
例子:
clear all;
x = input('entrer un chiffre entier impair : ');
if mod(x,2)==0
fprintf('%.0f n''est pas un chiffre entier impair \n',x);
else
str_space='';
for k=1:(x+1)/2
for n=1:1:(x-(2k-1)/2)/2
str_space=strcat(str_space,' ');
end
for n=1:(2k-1)
str_etoile=strcat(str_etoile,'*');
end
str_result=[str_space str_etoile str_space];
fprintf('%s \n',str_result);
end
end
系统说“for n=1:1:(x-(2k-1)/2)/2 ”有错误“Unexpected MATLAB expression.”。我不知道那里出错了,那一位朋友帮我找出为什么出错?谢谢!