String starting with ' and ending with '
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I have a function that calls a filename. The filename must be typed in with the string delimiter ' ' included into the argument. I have string variables holding the filenames. How do I call this function using the string variables and have the string delimiter explicitly passed to the function. If I just give it the variable name, it chokes because the delimiters are not there. Here is the structure of how the function opens the file.
function [A, B]=testfunction(file);
% [data, header]=testfunction(file)
% This function reads in a file and its header information
fid=fopen(file,'r','ieee-be');
. . .
Thanks,
Francois
0 Kommentare
Antworten (2)
Thomas
am 3 Jul. 2012
Bearbeitet: Thomas
am 3 Jul. 2012
Here is my function file
function [A,B]=readfunction(file)
file_name=file % donot need this just to show it goes to variable
fid=fopen(file_name);
end
Now if I give the following command
>> readfunction('hello.m')
file_name =
hello.m
It comes in without the ' ' delimiters.. and opens the file just fine..
2 Kommentare
Thomas
am 3 Jul. 2012
Bearbeitet: Thomas
am 3 Jul. 2012
you need to use the ' ' delimiter to call a file, you cannot do without.. and even if you use the ' ' delimiter in the calling the function the variable will not have the ' ' delimiter..
>> name='hello.m';
>> readfunction(name)
file_name =
hello.m
how ever if you want to use it again you need to add the single quotes to filename as
new=sprintf('''%s''',file_name)
readfunction(new)
Works as it should...
Walter Roberson
am 3 Jul. 2012
filenames = {'file1.txt', 'file2.txt', 'file3.txt'};
for K = 1 : length(filenames)
thisfile = filenames{K};
testfunction(thisfile)
end
0 Kommentare
Siehe auch
Kategorien
Mehr zu Characters and Strings finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!