Arranging JSON-formatted txt file

4 ビュー (過去 30 日間)
Divya
Divya 2022 年 11 月 21 日
コメント済み: Divya 2022 年 11 月 21 日
Hi,
I have JSON-formatted txt file from which I need to extract data and process it for further evaluation. This file contains values for 6 parameters and displays as 1x28272 table. How do I make these 6 parameters as seperate columns?
Any help would be great/
Thanks and Regards,
Divya
This is how my data looks :
{"phase":["328.17418282485926","98.13568811161387","267.3230213793066...........,"],"rssi":["....."],"halfrow":["......"],"tag":["........"],"time":["......"],"frequency":["....."]}
  2 件のコメント
KSSV
KSSV 2022 年 11 月 21 日
Explore functions like table2struct, table2cell.
Or attach your data along with the code you tried.
Divya
Divya 2022 年 11 月 21 日
This is what I tried :
RFID_data = readtable('tagdata_new_0_height_0_03_08_22_12');

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

採用された回答

Askic V
Askic V 2022 年 11 月 21 日
Maybe something like this:
raw = '{"phase":["328.17418282485926","98.13568811161387","267.3230213793066...........,"],"rssi":["....."],"halfrow":["......"],"tag":["........"],"time":["......"],"frequency":["....."]}';
data = jsondecode(raw); % Using the jsondecode function to parse JSON from string
data.phase
ans = 3×1 cell array
{'328.17418282485926' } {'98.13568811161387' } {'267.3230213793066...........,'}
data.rssi
ans = 1×1 cell array
{'.....'}
  3 件のコメント
Askic V
Askic V 2022 年 11 月 21 日
I would start with this (found on another thread)
fileName = 'tagdata_new_0_height_0_03_08_22_12.txt'; % filename in JSON extension
fid = fopen(fileName); % Opening the file
raw = fread(fid,inf); % Reading the contents
str = char(raw'); % Transformation
fclose(fid); % Closing the file
data = jsondecode(str); % Using the jsondecode function to parse JSON from string
fields = fieldnames(data);
phase = str2double(data.(fields{1}));
Divya
Divya 2022 年 11 月 21 日
This works perfectly!
Thanks,
Divya

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

その他の回答 (0 件)

カテゴリ

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

製品


リリース

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by