Use variable as placeholder in a path

20 ビュー (過去 30 日間)
Reuben Addison
Reuben Addison 2023 年 2 月 8 日
編集済み: VBBV 2023 年 2 月 8 日
I am trying to use a variable as a placeholder in a path but I keep getting an error.
data = dlmread(['/Users/reubs/Documents/Data/PO1/' cell2mat(filenames(trialnumber))],'',1,0);
I want to rewrite this as
path1 = '/Users/reubenaddison/Documents/Data/PO1/';
data = dlmread([fullfile(path1) cell2mat(filenames(trialnumber))],'',1;0);
but I get
"Invalid expression. When calling a function or indexing a variable, use parentheses. Otherwise, check for mismatched delimiters."

採用された回答

VBBV
VBBV 2023 年 2 月 8 日
編集済み: VBBV 2023 年 2 月 8 日
path1 = '/Users/reubenaddison/Documents/Data/PO1/';
data = dlmread(fullfile(path1, num2str(cell2mat(filenames(trialnumber)))),'',1,0);
% ^ convert num to str in fullfile ^^ use a , in place of ;
Matlab recommends to use readmatrix than using dlmread. Read dlmread

その他の回答 (1 件)

Image Analyst
Image Analyst 2023 年 2 月 8 日
Try this:
folder = '/Users/reubenaddison/Documents/Data/PO1/';
fullFileName = fullfile(folder, filenames{trialnumber}) % Use braces!
data = dlmread(fullFileName);
See the FAQ to learn when to use parentheses, braces, and brackets:

カテゴリ

Help Center および File ExchangeData Type Conversion についてさらに検索

製品


リリース

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by