convert list of strings to char arrays

3 views (last 30 days)
I have list of directories stored as strings, the variable containing this list is 1xN string. I need to pass them one by one in a loop to the fullfile() function. Unfortunately attempting this, Matlab says that "String input is not supported" for the fullfile function. Well then, how do I convert the strings to char vectors, please?

Accepted Answer

Stephen23
Stephen23 on 9 May 2018
Edited: Stephen23 on 9 May 2018
One at a time: char
Or all at once: convertstringstochars
  1 Comment
Walter Roberson
Walter Roberson on 9 May 2018
Edited: Walter Roberson on 9 May 2018
Note: this was needed for R2016b, the release which introduced string objects. If I recall correctly, by R2017a, fullfile() supported using string objects.
By the way, you might not need to loop. If you have a string object, say FileNames, and a folder, say ProjectDir, then
fullnames = fullfile(ProjectDir, cellstr(FileNames));
and now fullnames will be a cell array of character vectors in which the full name of each file has been created.

Sign in to comment.

More Answers (0)

Categories

Find more on Data Type Conversion in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!