# Thread: Getting Matlab to call a string

1. ## 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.

2. Originally Posted by nottheface
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.

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

3. 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