%% % Lots of array examples. % this shows many different ways to create the array: % [ 1 2 3 4 5 ] %% Just typing it in (OK since it is small) A = [ 1 2 3 4 5 ] A = [ 1,2,3,4,5 ] % note the difference for semicolon A = [ 1;2;3;4;5 ] %% use a loop (OK since it is small) A = zeros(1,5) for n=1:5; A(n) = n; end; A %% Use a colon, low:high A = 1:5 %% linspace A = linspace(1,5,5) %% how about an array that is not integers? % [0.5 1.0 1.5 2.0 2.5] A = (1:4) .* 0.5 A = 0.5:0.5:2.0 A = linspace(0.5, 2.0, 4) %% Or, just don't even bother defining it first % but watch why this is slow. for n = 1:5; B(n) = n end