-
Notifications
You must be signed in to change notification settings - Fork 0
/
for_loop
44 lines (39 loc) · 829 Bytes
/
for_loop
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
%% For Loop
clear all; close all; clc
v = input('Please enter a vector --> ');
sum = 0;
for i=1:1:length(v)
sum = sum + (v(i))^2;
end
%% Creating v vector containg all integers less than or
% equal to N that are prime number
N = input('Please enter a positive integer --> ');
primes = [];
for i=2:1:N
if isprime(i)
primes = [primes i];
end
end
%% For Loop- subplot
clear all; close all; clc
a = rand(11,4) % random matrix 11 rows 4 columns
a_re = 10*(0:10)'
a(:,1) = a_re
hold on
for i=2:1:4
plot(a(:,1),a(:,i),'--bo')
end
%% Subplot loop
x = 0:0.01:2*pi;
for i=1:1:3
subplot(1,3,i)
plot(x,sin(i*x));
end
%% for loop for creating values at s and y
x = linspace(0,5,1000);
y = x.*cos(x);
plot(x,y,'--b');
hold on
for i=100:100:1000
plot(x(i),y(i),'ks','MarkerFaceColor','k')
end