當(dāng)前位置:
首頁(yè) >
前端技术
> javascript
>内容正文
javascript
Matlab处理JSON数据
生活随笔
收集整理的這篇文章主要介紹了
Matlab处理JSON数据
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
Matab需要對(duì)C#的數(shù)據(jù)進(jìn)行處理。采用JSON格式相對(duì)來說比較方便。
定義的JSON格式如下
{"datas":[[{"X":11,"Y":12,"Z":13,"A":1,"B":11,"C":111},{"X":1201,"Y":1202,"Z":2,"A":1,"B":11,"C":111}],[{"X":21,"Y":22,"Z":23,"A":1,"B":11,"C":111}],[{"X":11,"Y":12,"Z":13,"A":1,"B":11,"C":111},{"X":1201,"Y":1202,"Z":2,"A":1,"B":11,"C":111}]] }下面是利用JsonLib()處理JSON的例子
% 數(shù)據(jù)點(diǎn) fname='data3d.json'; %待讀取的文件名稱 if(exist(fname,'file')==0) break; end opt.SimplifyCell=0; %解析選項(xiàng) jsonData=loadjson(fname,opt) ; datas=jsonData.datas; % datas{2}{1}.Z %訪問數(shù)據(jù)的格式 str=[]; disp(['total Row:',num2str(length(datas))]);% 遍歷 for i=1:length(datas)row= datas{i};%for j=1:length(row)cell=row{j};disp(cell.X);end end% 增加新的一行(Cell),新行包含兩個(gè)cell,每個(gè)cell中就是一個(gè)struct disp(str); point1.X=1; point1.Y=2; point1.Z=4; newIndex=length(datas)+1; point2.A=1; point2.B=1; point2.C=1; datas{newIndex}={point1,point2}; % 編碼時(shí)的選項(xiàng) opt.Compact=1; opt.FileName='newjson.json'; json=savejson('datas',datas,opt);?
總結(jié)
以上是生活随笔為你收集整理的Matlab处理JSON数据的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 使用Postgrest快速创建数据库的O
- 下一篇: 使用puppeteer爬 EXTJS