Writting data to text file (json)
305 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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.
0 commentaires
Réponse acceptée
Chris
le 24 Oct 2021
See jsonencode()
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 commentaires
Pippa Williams
le 10 Fév 2022
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
le 10 Fév 2022
Modifié(e) : Chris
le 10 Fév 2022
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.
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur JSON Format dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!