Variable as placeholder in an "fopen" statement

Still on the issue of a place holder , I am trying to write a code to name the output folder by subject name, I know typically it goes into the braces but this time arround it is not working
''
subject = "PO1"
fid = fopen(['/Users/addison/Documents/Data/"Results2"+{subject}.xls'],'w');
''

1 个评论

"I know typically it goes into the braces..."
"...but this time arround it is not working"
which is not a big surprise with MATLAB.

请先登录,再进行评论。

 采纳的回答

The way I would do this is this
subject = "PO1";
folder = "/Users/addison/Documents/Data/";
filename = "Results2" + subject + ".xls"
filename = "Results2PO1.xls"
fid = fopen(fullfile(folder, filename));

更多回答(0 个)

类别

帮助中心File Exchange 中查找有关 Get Started with MATLAB 的更多信息

产品

版本

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by