Question

I have a .csv file which contains stock information of Amazon

date,       closePrice, volume,  openPrice, highPrice, lowPrice
=============================================================== 
30/10/2013  361.08      4500014  362.62     365         358.65
29/10/2013  362.7       2184755  358.96     362.89      356.29
28/10/2013  358.16      3602497  359.92     362.75      357.2
25/10/2013  363.39      12034820 358.6      368.4       352.62
24/10/2013  332.21      5699188  329.63     332.6499    326.75

I have loaded this file into Matlab and now i would like to read data from this file in order to produce candlestick chart. this is what I done:

clear;
close all;

file = '/Users/Documents/MATLAB/Candlestick Chart/Amazon.csv';

candle (file(:,2), file(:,3),file(:,4),file(:,5), 'b', file(:,1))

 set(file(:,5), 'FaceColor', 'g')
 set(file(:,6), 'FaceColor', 'r')

when running .m file i am getting error saying:

Error using dlmread (line 139)
Mismatch between file and format string.
Trouble reading number from file (row 1u, field 2u) ==>
/10/2013,361.08,4500014,362.62,365,358.65\n

Error in csvread (line 48)
    m=dlmread(filename, ',', r, c);

I know the software is failing to convert date into vector, can anyone help me convert date into vector and plot a candle-chart. So in X access I want to display date and based on high, low, closing, opening price i want to plot a candle chart.

Was it helpful?

Solution

You can use textscan

 fid = fopen(filename, 'r')
 C = textscan(fid, '%s%f%f%f%f%f', 'Headerlines', 2);
 fclose(fid)

then use vectors in C{2}, C{3}, ... for your plot.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top