How can I access the value of a string variable? I need to construct a file path from a string variable, but keep getting the variable name and not the string.
I want to construct a file path, "f" that I will use many times in a Matlab m file. From advice in an answer to someone else’s question, I am using the "fullfile" function. However, I am having what seems like a silly problem. Please see the example below.
I want to put "directory1" in the file path to get:
/Users/me/ch4/directory1/directory2/results/file_1.dat
However, when I do:
directory_name = "directory1";
f = fullfile(‘/Users/me/ch4’, directory_name, ‘directory2/results/file_1.dat’)
I get:
Error using matlab.io.ImportOptions/readtable (line 503)
Unable to find or open ‘/Users/me/ch4/directory_name/directory2/results/file_1.dat’. Check the path and filename or file permissions
How can I substitute the contents of the variable and not the variable name in the file path? Thank you for any advice.I want to construct a file path, "f" that I will use many times in a Matlab m file. From advice in an answer to someone else’s question, I am using the "fullfile" function. However, I am having what seems like a silly problem. Please see the example below.
I want to put "directory1" in the file path to get:
/Users/me/ch4/directory1/directory2/results/file_1.dat
However, when I do:
directory_name = "directory1";
f = fullfile(‘/Users/me/ch4’, directory_name, ‘directory2/results/file_1.dat’)
I get:
Error using matlab.io.ImportOptions/readtable (line 503)
Unable to find or open ‘/Users/me/ch4/directory_name/directory2/results/file_1.dat’. Check the path and filename or file permissions
How can I substitute the contents of the variable and not the variable name in the file path? Thank you for any advice. I want to construct a file path, "f" that I will use many times in a Matlab m file. From advice in an answer to someone else’s question, I am using the "fullfile" function. However, I am having what seems like a silly problem. Please see the example below.
I want to put "directory1" in the file path to get:
/Users/me/ch4/directory1/directory2/results/file_1.dat
However, when I do:
directory_name = "directory1";
f = fullfile(‘/Users/me/ch4’, directory_name, ‘directory2/results/file_1.dat’)
I get:
Error using matlab.io.ImportOptions/readtable (line 503)
Unable to find or open ‘/Users/me/ch4/directory_name/directory2/results/file_1.dat’. Check the path and filename or file permissions
How can I substitute the contents of the variable and not the variable name in the file path? Thank you for any advice. string, strings, variable, variables MATLAB Answers — New Questions