Call a Function in Another Function, Prepare the Argument as a String
Show older comments
Hi there!
I have a function that takes input of the following form:
myFun({'.\file1.dat','.\file2.dat'},{'DataIdentifier'},'option','optionvalue')
I would like to create the input in another function and tried with creating this a character array:
function [ ] = myCall
%%Setup
myDir = './';
myIni = 'file';
myFiles = 1:10;
myLevel = '.dat';
myInterest = '{''var1''}';
myOptions = '''xvariable'',''y''';
%%Run
allFiles = '';
for i = myFiles
allFiles = [allFiles ''',''' myDir myIni '0' char(string(i)) myLevel];
end
myString = ['{''' allFiles(4:end) '''}'];
myFun(myString,myInterest,myOptions)
end
Now, myFun returns
Error using fgets
Invalid file identifier. Use fopen to generate a valid file identifier.
Is there a general limitation in passing character arrays or strings as input to a function in MATLAB? Because, when I copy myString and paste it into myFun in the Command Window, it works.
Thank you very much in advance for your help on that matter! :)
Accepted Answer
More Answers (0)
Categories
Find more on Data Type Identification 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!