Improved programming chapter

This commit is contained in:
2015-11-29 15:48:15 +01:00
parent 3e0f8c10a1
commit 2c389639dc
15 changed files with 740 additions and 608 deletions

View File

@@ -3,5 +3,6 @@ counter = 1;
x = 1;
while counter <= n
x = x * counter;
counter = counter + 1
end
fprintf('Faculty of %i is: %i\n', n, x)
fprintf('Faculty of %i is: %i\n', n, x)

View File

@@ -3,18 +3,16 @@ if x < 0.5
disp('x is less than 0.5');
end
if x < 0.5
disp('x is less than 0.5!');
else
disp('x is greater than or equal to 0.5!')
end
if x < 0.5
disp('x is less than 0.5!');
elseif x < 0.75
disp('x is greater than 0.5 but less than 0.75!');
else
disp('x is greater than or equal to 0.75!')
end
end

View File

@@ -1,12 +1,12 @@
t = 0:0.001:10;
x = randn(size(t));
selection = x (t > 5 & t < 6);
selection = x(t > 5 & t < 6);
figure()
hold on
plot(t, x, 'displayname', 'measurements')
plot(t(t > 5 & t < 6), selection, 'displayname', 'selection')
xlabel('time [s]')
ylabel('intensity')
xlabel('Time [s]')
ylabel('Intensity')
legend 'show'
box 'off'
box 'off'

View File

@@ -1,12 +1,10 @@
>> logicalVector
Logischer Vektor y:
y =
1 1 1 1 0 0 0 0 0 0
Datentyp von y: logical
Alle Elemente aus x, die kleiner als 5 sind:
ans =
1 2 3 4

View File

@@ -1,14 +1,3 @@
a = (11:20); % a vector with 10 Elements
fprintf('length of a: %i\n', length(a))
size_of_a = size(a); % get the size and store it in a new variable
% size_of_a is a vector itself
fprintf('number of dimensions (rank) of size_of_a: %i\n', length(size_of_a))
% get the value of the second element of size_of_a
fprintf('number of entries in the 2nd dimesion of a: %i\n', size_of_a(2))
%% Uebersichtliche Alternative?
s = size(a); % Speicher den Rueckgabewert von size() in einer Variablen
s(2) % Inhalt der zweiten Zahl, d.h. Laenge der 2. Dimension
size(a,2) % Kurze Alternative
s = size(a) % Speicher den Rueckgabewert von size() in einer Variablen
s(2) % Inhalt der zweiten Zahl, d.h. Laenge der 2. Dimension
size(a,2) % Die kurze Alternative

View File

@@ -1,4 +1,3 @@
>> vectorsize
length of a: 10
number of dimensions (rank) of size_of_a: 2
number of entries in the 2nd dimesion of a: 10
s = 1 10
ans = 10
ans = 10