Need to convert char to struct
古いコメントを表示
I am trying to use a trading algorithm and I need to check prices daily. I can download the prices manually and load them into matlab manually, but I don't want to do that every single day. I get the data from quandl.com and when I use urlread on the data file, it returns a char of the data with each value separated with a comma. How can I convert this to a structured array in my program? Should I be using a different command besides urlread for this? I've tried using struct() on the char variable but is doesn't work.
回答 (2 件)
Walter Roberson
2014 年 4 月 13 日
0 投票
I recommend using regexp() with the 'split' option to get the text for each number into its own cell array entry, and then str2double() the overall cell array to get the numeric values. Or if you know exactly how many data values are expected, you could sscanf() on the strings.
3 件のコメント
Paul
2014 年 4 月 13 日
Walter Roberson
2014 年 4 月 13 日
ewa2 = regexp(ewa, ',\s*', 'split');
ewa3 = str2double(ewa2);
Paul
2014 年 4 月 13 日
Azzi Abdelmalek
2014 年 4 月 13 日
str='12.03,23,25,26,30'
a=struct('data',num2cell(str2double(regexp(str,'[\w\.]+','match'))))
4 件のコメント
Paul
2014 年 4 月 13 日
Azzi Abdelmalek
2014 年 4 月 13 日
編集済み: Azzi Abdelmalek
2014 年 4 月 13 日
a=regexp(ewa,'[^,\s]+','match')
str=reshape(str,2,[])'
dates=str(2:end,1)
price=str2double(str(2:end,2))
Image Analyst
2014 年 4 月 13 日
I think you mean "dates" since date is the name of a built in function.
Azzi Abdelmalek
2014 年 4 月 13 日
Exact
カテゴリ
ヘルプ センター および File Exchange で Data Type Conversion についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!