I am new to Matlab, I was wondering how do i read 1st row and 2nd row from a .CSV file. This is what I have done:
str = urlread('http://ichart.yahoo.com/table.csv?s=AMZN&a=0&b=1&c=2014&d=0&e=31&n=2014&g=d&ignore=.csv'); i = 0; [dates,o,h,l,c] = dataread('string',str,'%s%f%f%f%f%*f%*f','delimiter',',','headerlines',1); dates = datenum(dates); firstDate = dates(2) secondDate = firstDate(3) if () i = i+1; end
At the moment I can get the first row and second row, but what I need is the final row and final row +1. So from backward compare two rows at the time. Check if open price number in first row is grater than open price number from the second row (bottom up) if yes +1 and save file. For example from the above file the last few files looks like this:
Date,Open,High,Low,Close,Volume,Adj Close 2014-01-17,394.26,403.49,393.66,399.61,4505100,399.612014-01-16,393.68,399.29,389.41,395.80,2601200,395.802014-01-15,398.94,399.31,392.53,395.87,2678300,395.872014-01-14,392.13,398.63,391.29,397.54,2340100,397.542014-01-13,397.98,399.78,388.45,390.98,2844900,390.982014-01-10,402.53,403.76,393.80,397.66,2679500,397.662014-01-09,403.71,406.89,398.44,401.01,2103000,401.012014-01-08,398.47,403.00,396.04,401.92,2316500,401.922014-01-07,395.04,398.47,394.29,398.03,1916000,398.032014-01-06,395.85,397.00,388.42,393.63,3170600,393.632014-01-03,398.29,402.71,396.22,396.44,2210200,396.442014-01-02,398.80,399.36,394.02,397.97,2137800,397.97 So take 1st and 2nd lines below the file e.g. 2014-01-03,398.29,402.71,396.22,396.44,2210200,396.44 2014-01-02,398.80,399.36,394.02,397.97,2137800,397.97
Now compare if 398.80>398.29 if yes +1 in file. Once this is done go on to 2nd and 3rd line e.g.:
2014-01-06,395.85,397.00,388.42,393.63,3170600,393.632014-01-03,398.29,402.71,396.22,396.44,2210200,396.44
Now compare if 398.29>395.85 if yes +1 in the file so (2) etc.. do it till the first file in the list.
Best Answer