convert char array to string
45 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Antoine Masia
le 20 Juin 2022
Modifié(e) : Cris LaPierre
le 20 Juin 2022
between 2019b ans 2021b, function "fileparts" returned String instead of char, this caused many change in my code. iIs there away to obtain the legacy behavior in 2021b ?
thank
0 commentaires
Réponse acceptée
Cris LaPierre
le 20 Juin 2022
Modifié(e) : Cris LaPierre
le 20 Juin 2022
The function fileparts creates output with the same data type as the input.
% String input = string output
fileS = "H:/user4/matlab/myfile.txt";
[filepath,name,ext] = fileparts(fileS)
% Char array input = char array output
fileC = 'H:/user4/matlab/myfile.txt';
[filepath,name,ext] = fileparts(fileC)
Check what you are using for input. You could use the convertStringsToChars function to convert your input to fileparts to char if necessary.
[filepath,name,ext] = fileparts(convertStringsToChars(fileS))
Or simply char(string), as Fangjun showed
[filepath,name,ext] = fileparts(char(fileS))
Plus de réponses (1)
Voir également
Catégories
En savoir plus sur Cell Arrays 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!