MATLAB Answers

Fullfile function gives me a false reading with the slash symbol

1 view (last 30 days)
AA on 29 Mar 2020
Edited: Stephen Cobeldick on 30 Mar 2020
fileToRead = fullfile('C:\Users\thomas\Files\' CCC '.csv');
CCC is a string file with CCC='Tax'
I get the following:
but I want the following

  1 Comment

Stephen Cobeldick
Stephen Cobeldick on 30 Mar 2020
Note to future readers: Peng Li's answer shows the recommended solution.

Sign in to comment.

Accepted Answer

Peng Li
Peng Li on 29 Mar 2020
fileToRead = fullfile('C:\Users\thomas\Files\', [CCC '.csv']);


Sign in to comment.

More Answers (1)

darova on 29 Mar 2020
Try this
Or you can remove slash symbol
fileToRead(end-5) = [];

  1 Comment

Stephen Cobeldick
Stephen Cobeldick on 30 Mar 2020
There is absolutely no point in doing this:
This answer confuses two different ways of creating the full filename: string concatenation OR using fullfile. It makes absolutely NO sense to combine the two as shown in this answer, which has all of the disadvantages of string concatenation (no automatic handling of the slash/backslash) and only one input to fullfile (thus making it totally superfluous anyway).
I strongly recommend that users read about fullfile before blindly copying this answer.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!

Translated by