أمثلة ماتلاب Matlab Examples using for Loop
- 2021-03-20
توصيف
صيغة حلقة for:
for index = values
end
برنامج طباعة الأعداد من 1 إلى 100:
for a =1:100
disp(a)
end
برنامج طباعة الأعداد من 100 إلى 1:
for a =100 :-1:0.0
disp(a)
end
برنامج إنشاء مصفوفة ذات أرقام عشوائية ثم طباعة الأعداد الموجبة منها فقط :
n = 1000; % Length of Array
n_positive=0; % how many positive number in array
a=randn(n,1); % Create a random array with n row and 1 coulmn
for i =1:length(a)
if (a(i)>0) % test if arry member (i) positive
disp(a(i))
n_positive=n_positive+1;
end
end
n_positive
برنامج طباعة الأعداد من 1 إلى 0 بخطوة 0.2:
for v = 1.0:-0.2:0.0
disp(v)
end