Help in Syntax of Eval and Sprintf
3 次查看(过去 30 天)
显示 更早的评论
Hi,
I want to run the following expression:
*X = fts2mat(ESP('01-Jan-97::31-Dec-2012'))*
The above statemement works fine. ESP is my financial time seris(fts) container. I am getting the desired results in X.
But now I wish the dates to be passed from a cell array of date strings I have as mydate1{} and mydate2{} in place of the datestrings given in the first statement. I think it can be done via
*eval(sprintf(fts2mat(ESP('mydate1''::''mydate2'))));*
But the above gives error.
Help will be highly appreciated.
Regards,
AMD.
0 个评论
采纳的回答
ChristianW
2013-3-14
Y = cell(size(mydate1)); % preallocate
for k = 1:length(mydate1)
str = [mydate1{k} '::' mydate2{k}]; % Date String Range
% str = sprintf('%s::%s',mydate1{k},mydate2{k}); % Alternative
Y{k} = fts2mat(EPS(str)); % output saved in cell Y
end
2 个评论
ChristianW
2013-3-14
doc sprintf
An example:
sprintf('answer=%d',3) % ans = 'answer=3'
sprintf('%d is the answer',3) % ans = '3 is the answer'
The Symbol %d determines where the variable (3) is placed in the string. Same with %s, s announces that the variable is a string.
sprintf('answer=%s','HELLO')
sprintf('%s is the answer','HELLO')
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Calendar 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!