How do I include a variable when trying to display a string?
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Omar Abedalrahman
el 3 de Sept. de 2016
I created a start time and saved it. I want to include this variable in the end of the string, but what I'm doing is not working. Here is my current code:
startHW1=datetime('now');
save HW1 startHW1
disp(['I started HW1 on ', num2str(startHW1)]);
0 comentarios
Respuesta aceptada
dpb
el 3 de Sept. de 2016
Editada: dpb
el 3 de Sept. de 2016
Use the optional output format
startHW1=datetime('now','Format','dd-MMM-yyyy HH:mm:ss');
disp(['I started HW1 on ' startHW1])
or, just use now
startHW1=now;
disp(['I started HW1 on ' datestr(startHW1)])
(Addendum/Erratum: the need for datestr here sorta' defeats the purpose; my faux pas explained further in comment to Stephen...)
2 comentarios
Stephen23
el 3 de Sept. de 2016
Editada: Stephen23
el 3 de Sept. de 2016
That second example does not make any sense:
>> startHW1=now;
>> disp(['I started HW1 on ' startHW1])
Warning: Out of range or non-integer values truncated during conversion to character.
I started HW1 on
>>
Why do you want to join character 736576 (or similar) onto the end of that string?
A datestr call is most likely required here...
Más respuestas (0)
Ver también
Categorías
Más información sobre String Parsing en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!