Writting data to text file (json)

조회 수: 439 (최근 30일)
Nagesh Ardjoon
Nagesh Ardjoon 2021년 10월 24일
편집: Chris 2022년 2월 10일
I am trying to write images annotation information to a text file in json format for futher usage in another programming language. I am not well versed in MATLAB therefore I've been stuck in finding a solution to my problem even after querying the web. The annotations and images are available from this link.
I have attached a sample of the required format in which the information should be extracted. I hope somone can help me out with a script which would serve my purpose.
Thank you.

채택된 답변

Chris
Chris 2021년 10월 24일
To write the encoded data "encoded" to file:
fid = fopen('file.json','w');
fprintf(fid,'%s',encoded);
fclose(fid);
For a bit more detail on the file handling:
https://www.mathworks.com/matlabcentral/answers/504472-how-to-update-json-file-with-matlab
  댓글 수: 6
Pippa Williams
Pippa Williams 2022년 2월 10일
Hi folks,
I have a similar issue, but I need the variable names to start with a number (I cannot change these). I'm assuming the only way is to put some identifier at the start of the variable name which can be easily deleted afterwards. Is there a better solution I'm not thinking of?
e.g. if the variable name is 30min_horizon, I'll use something like NUMNAME_30min_horizon.
Then use: erase(jsonstring,"NUMNAME_");
Thanks for your help so far!
Pippa
Chris
Chris 2022년 2월 10일
편집: Chris 2022년 2월 10일
Hi Pippa,
If you can do that, it's pretty clever and likely one of the easiest solutions.
You could possibly try constructing a loop like the one three posts up (or a more comprehensive, error-tolerant set of functions, if you'll be doing this often), but if you're dealing with a map or struct and are able to insert that prefix without trouble, that would be the approach I'd take.
If you're still having trouble, feel free to post a new question and upload or point to some example data. Someone with relevant experience might see it on the front page and have a different answer.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

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