Using Java UUID in Matlab
16 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I am trying to use JAVA UUIDs to identify the objects in my code. When I try to print it inside an fprintf, I get a weird error. I could print it in disp but that is not ideal since I want a good formatted message.
>> temp = java.util.UUID.randomUUID;
>> myuuid = temp.toString;
>> disp(myuuid)
a8a4eae2-6cc7-47d3-b58e-408b71fab260
>> fprintf(myuuid)
Error using fprintf
Invalid file identifier. Use fopen to generate a valid file identifier.
Any help in understanding or fixing this error is appreciated.
1 comentario
David Galbally
el 21 de Ag. de 2021
>> temp = java.util.UUID.randomUUID;
>> myuuid = temp.toString;
>> MATLABstr = myuuid.toCharArray';
>> fprintf(MATLABstr)
Respuestas (3)
Walter Roberson
el 7 de Sept. de 2015
Editada: Walter Roberson
el 7 de Sept. de 2015
Try
fprintf('%s\n' myuuid);
If that doesn't work then
fprintf('%s\n', char(myuuid));
3 comentarios
Walter Roberson
el 7 de Sept. de 2015
It appears that I was adding a second option to my answer just as you replied. Did you get a chance to try
fprintf('%s\n', char(myuuid));
Emile Glorieux
el 26 de Ag. de 2020
This doesn't work for me.
>> fprintf('%s\n', char(myuuid));
Undefined function or variable 'myuuid'.
Philipp Tempel
el 17 de Mzo. de 2022
This may be too stupid to be true but, looking at the source code of tempname(), you can see that you can simply do
uuid = char(matlab.lang.internal.uuid())
1 comentario
Andrei Veldman
el 17 de Mzo. de 2022
Editada: Andrei Veldman
el 17 de Mzo. de 2022
True, but then you would be using an undocumented Matlab feature, which could change without warning...
Andrei Veldman
el 19 de En. de 2022
...or, using pure Matlab (no need for converting form Java):
[~,guid] = fileparts(tempname)
0 comentarios
Ver también
Categorías
Más información sobre Startup and Shutdown en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!