%% F van der Heijden - test the speed of matrix-vector multiplication %% clear all close all clear variables %% set parameters N = 1000; % number of elements in x M = 5000; % number of elements in y %% initialize arrays H = randn(M,N); % create a random MxN matrix for testing x = randn(N,1); % create a random Nx1 array for testing %% perform a naive matrix-vector multiplication tic % start stopwatch y = zeros(M,1); % pre-alllocate y array and fill with zeros for m=1:M % loop through elements of y for n=1:N % loop through elements of x y(m) = y(m)+H(m,n)*x(n); % perform the calculation end end toc % read elapsed time from stopwatch