フィルターのクリア

How get values from ch

14 ビュー (過去 30 日間)
JM_Cortes
JM_Cortes 2019 年 6 月 10 日
編集済み: Bob Thompson 2019 年 6 月 10 日
Hello i got this ch in workspace and i want to get the values "price" from it for plot them, how can i put in a cell?
I got this.
[{"date": "1560160129", "tid": 90322567, "price": "7727.41", "type": 0, "amount": "0.00783400"}, {"date": "1560160115", "tid": 90322553, "price": "7725.96", "type": 0, "amount": "0.08018985"}]
Thank you
Regards
  2 件のコメント
Bob Thompson
Bob Thompson 2019 年 6 月 10 日
編集済み: Bob Thompson 2019 年 6 月 10 日
If I am interpretting what you have posted correctly you have two cells, each which contain five strings, and you want to extract the numeric value following 'price'? How are you importing the data, does it need to be in strings?
With what you have now I would suggest using a combination of regexp, str2num, and possibly strfind.
EDIT** I just realized that all of the links were incorrect. They have been fixed.
JM_Cortes
JM_Cortes 2019 年 6 月 10 日
編集済み: JM_Cortes 2019 年 6 月 10 日
Its a cell with 1x9600 char, the data is taken froma an api exchange, i want to extract the numeric price.

サインインしてコメントする。

採用された回答

Bob Thompson
Bob Thompson 2019 年 6 月 10 日
As far as I can tell the easiest way to do what you're asking would be something like the following:
price = str2num(regexp(string,'"price": "(\d*.\d*)"','tokens'));
You may have some issues with cells being too deep, but you can pull the price information further out if needed.
  2 件のコメント
JM_Cortes
JM_Cortes 2019 年 6 月 10 日
Thanks it works if i dont use str2num and i got the values like this: 1×100 cell array
Columns 1 through 8
{1×1 cell} {1×1 cell} {1×1 cell} {1×1 cell} {1×1 cell} {1×1 cell} {1×1 cell} {1×1 cell}
.......
If i use str2num i got this:
Error using str2num (line 35)
Input must be a character vector or string scalar.
With str2double i got NaN
Bob Thompson
Bob Thompson 2019 年 6 月 10 日
So, this is what I was saying by having extra depth to the array (each cell you see contains a 1x1 cell with the actual string). Personally, I find it very frustrating to deal with, but regexp is too useful for working with strings to ignore. Luckily, in this case the solution is fairly simple.
ps = regexp(string,'"price": "(\d*.\d*)"','tokens');
ps = [ps{:}];
price = str2double(ps);

サインインしてコメントする。

その他の回答 (1 件)

JM_Cortes
JM_Cortes 2019 年 6 月 10 日
I got it with: cellfun(@str2double,string)
Thank you
Regards!!

カテゴリ

Help Center および File ExchangeString についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by