Matlab - Invalid file identifier. Error in savejson

I am new to Matlab and jsonlab. I am trying to create a json file from Matlab (R2015a / Windows10) using JsonLab but I keep getting the following error:

Error using fwrite Invalid file identifier. Use fopen to generate a valid file identifier. Error in savejson (line 160) fwrite(fid,json,'char'); 

And line 160 in the savejson jsonlab function:

 fid = fopen(filename, 'wt'); fwrite(fid,json,'char'); 
+5
source share
1 answer

The third entry in savejson is the file in which you need to save the received JSON data. In the example you provided

 savejson('',x,'data/matlabData.json') 

This is an attempt to create a matlabData.json file in the data folder. savejson does not work because the data folder does not exist and therefore the file cannot be created.

You can create a data folder

 mkdir('data') savejson('', x, fullfile('data', 'matlabData.json')) 

Or you can use your own file name, which does not require a folder

 savejson('', x, 'matlabData.json') 
+1
source

Source: https://habr.com/ru/post/1265784/


All Articles