Results 1 to 3 of 3

Math Help - Getting Matlab to call a string

  1. #1
    Newbie
    Joined
    Feb 2010
    Posts
    9

    Getting Matlab to call a string

    I'm working on this program which involves a CSV file of Apple's Stock from the last ten years. It is composed of ten tasks. Task 1 wants me to find what the stock's highest ever closing price was and when did it occur. The answer should be

    “This stock's highest ever closing price was $215.04, which occurred on 19-Jan-10”

    The variables open, hi, lo, close, and vol are vectors and the variable date is a cell array.

    Now we have to make Matlab read data from this CSV file. Here is the coding I have so far

    [date,open,hi,lo,close,vol] = textread('apple.csv','%s%f%f%f%f%f','delimiter',', ','headerlines',1);

    highclose = max(close);

    fprintf('This stocks highest ever closing price was $%.2f, which occurred on %s \n',highclose)
    fprintf('\n')

    I have no idea how to get the date to display. I cannot simply just make a variable for the date though. Such as, I cannot make time=date{9} and insert it into the fprintf code to get 19-Jan-10 to display.

    This is because if my program were to read different data, it would get the highest closing price correct because "highclose=max(close)" will choose the highest number regardless if new data is loaded but then my date would be incorrect.

    Can anyone aid me please?
    Follow Math Help Forum on Facebook and Google+

  2. #2
    Junior Member
    Joined
    Feb 2010
    From
    New Jersey
    Posts
    73
    Quote Originally Posted by nottheface View Post
    I'm working on this program which involves a CSV file of Apple's Stock from the last ten years. It is composed of ten tasks. Task 1 wants me to find what the stock's highest ever closing price was and when did it occur. The answer should be

    “This stock's highest ever closing price was $215.04, which occurred on 19-Jan-10”

    The variables open, hi, lo, close, and vol are vectors and the variable date is a cell array.

    Now we have to make Matlab read data from this CSV file. Here is the coding I have so far

    [date,open,hi,lo,close,vol] = textread('apple.csv','%s%f%f%f%f%f','delimiter',', ','headerlines',1);

    highclose = max(close);

    fprintf('This stocks highest ever closing price was $%.2f, which occurred on %s \n',highclose)
    fprintf('\n')

    I have no idea how to get the date to display. I cannot simply just make a variable for the date though. Such as, I cannot make time=date{9} and insert it into the fprintf code to get 19-Jan-10 to display.

    This is because if my program were to read different data, it would get the highest closing price correct because "highclose=max(close)" will choose the highest number regardless if new data is loaded but then my date would be incorrect.

    Can anyone aid me please?
    Hi. I'm really new to Matlab, but I displayed dates in my homework like this:

    Code:
    fprintf(fid, ['Problem 5.1 - ' datestr(now) '\r\n\r\n']);
    Edit: Here is a better method that I just came up with for my own purposes:

    Code:
    find(not(deck(:)~=date))
    deck(~=date -- creates a vector with a one for each position whose value does not equal 'date'.
    not(the vector from last step) -- sets a one in each position that equals 'date'.
    find() -- returns the index of each position with a 1 in it.

    Good luck,
    -Jef
    Last edited by MSUMathStdnt; February 4th 2010 at 07:42 PM.
    Follow Math Help Forum on Facebook and Google+

  3. #3
    Grand Panjandrum
    Joined
    Nov 2005
    From
    someplace
    Posts
    14,972
    Thanks
    4
    At the command prompt type:

    help max

    does what it replies have a line with something like:

    [C,I]=max(...)

    If it does read the accompanying text.

    CB
    Follow Math Help Forum on Facebook and Google+

Similar Math Help Forum Discussions

  1. Why call it the Binomial Theorem?
    Posted in the Advanced Statistics Forum
    Replies: 2
    Last Post: February 25th 2011, 02:16 PM
  2. Balls (don't know what else to call it)
    Posted in the Differential Geometry Forum
    Replies: 1
    Last Post: April 17th 2010, 03:26 AM
  3. A puzzle and a call for help.
    Posted in the Math Puzzles Forum
    Replies: 14
    Last Post: August 23rd 2009, 07:39 PM
  4. call maple routine in matlab
    Posted in the Math Software Forum
    Replies: 0
    Last Post: April 25th 2009, 04:32 AM

Search Tags


/mathhelpforum @mathhelpforum