Import json files into Matlab and interpolate to every 0.1m

조회 수: 18 (최근 30일)
Justine
Justine 2022년 11월 6일
답변: Rahul 2024년 11월 7일 7:48
Hello! :)
How can I import several json files (.json) into matlab and interpolate the "Value.position.z" column to every 0.1m? I have a total of 2100 .json files that I need to interpolate and I need to find a way to interpolate all of the data using MATLAB.
Kindly find attached sample data in excel (Sample.xlsx) and screenshot of json file (Sample.png) for reference.
I hope someone can help. Thank you!

답변 (1개)

Rahul
Rahul 2024년 11월 7일 7:48
I understand that you require to interpolate 'Value.position.z' from 'json' files to every 0.1m. This can be done with the help of 'jsondecode' function to extract the 'json' file data with using 'fopen' and 'fread' to read the data. The 'interp1' function can be used to interpolate the data according to the requirement. Here is an example:
% Reading the 'json' file data
fid = fopen(filePath);
rawData = fread(fid, inf);
str = char(rawData');
fclose(fid);
% Parse JSON data
jsonData = jsondecode(str);
zData = [jsonData.Value.position.z];
zInterpPoints = 0:0.1:10; % Adjust the range as needed
interpolatedData{k} = interp1(zData, zData, zInterpPoints, 'linear');
% Here I have used 'linear' interpolation, it can be changed according to requirements
If required to read data from an 'xlsx' file, you can use 'readtable' function like this:
dataTable = readtable(filePath);
zColumn = dataTable.('Value.position.z');
You can refer to the following MathWorks documentations to know more about these functions:
Hope this helps! Thanks.

카테고리

Help CenterFile Exchange에서 JSON Format에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by