%connect to the database
conn = database('stocks','root','***','com.mysql.jdbc.Driver','jdbc:mysql://localhost:3306/stocks');
%query the symbols in the database
str_query_close = 'SELECT close, volume FROM stock_prices_minute WHERE symbol = ''GOOG''';
close_cell = fetch(conn, str_query_close);
for i = vwap_length:length(close_times_volume)
volume_total = 0;
volume_price_sum = 0;
for j = 0:(vwap_length - 1)
volume_total = volume_total + volume_mat(i-j);
volume_price_sum = volume_price_sum + volume_mat(i-j)*close_mat(i-j);
end
vwap(i-(vwap_length - 1)) = volume_price_sum / volume_total;
end
for i = vwap_length_2:length(close_times_volume)
volume_total = 0;
volume_price_sum = 0;
for j = 0:(vwap_length_2 - 1)
volume_total = volume_total + volume_mat(i-j);
volume_price_sum = volume_price_sum + volume_mat(i-j)*close_mat(i-j);
end
vwap_2(i-(vwap_length_2 - 1)) = volume_price_sum / volume_total;
end
x = [1:length(close_mat)];
x2 = [(vwap_length):length(close_mat)];
x3 = [(vwap_length_2):length(close_mat)];
plot(x, close_mat)
hold on
plot(x2, vwap, '-r')
hold on
plot(x3, vwap_2, '-g')
Mathworks also provides an example on their website.