create string with characters in char array

3 visualizaciones (últimos 30 días)
Francis Dick
Francis Dick el 16 de Mzo. de 2018
Comentada: Francis Dick el 16 de Mzo. de 2018
Hi,
I have a char array, which I want to use to name a .mat file into which i will save a couple of variables:
Name Size Bytes Class Attributes
str 1x4 8 char
str = F024
str contains only the characters: 'F024'. I want to use the 'save' function to save some variables with the filename being F024. I have tried using:
save(str,variable1,variable2,'-append');
however, an error is returned stating that the argument must contain a string.
Is there a way to convert the char array to a string? I don't want to manually enter the filename as it would mean that the data processing I am doing would take far longer.
Unfortunately I cannot use convertCharsToStrings as my university is running MATLAB v.R2016a.
Thanks.

Respuesta aceptada

Guillaume
Guillaume el 16 de Mzo. de 2018
The problem is not with your str variable, which is perfectly fine, but with the variable1 and variable2 which must be a string or char array containing the names of the variables, not the variables themselves, i.e.:
save(str, 'variable1', 'variable2', '-append');
not
save(str, variable1, variable2, 'append');
  1 comentario
Francis Dick
Francis Dick el 16 de Mzo. de 2018
of course it was something this simple! Thank you.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Workspace Variables and MAT Files 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!

Translated by