String starting with ' and ending with '
조회 수: 6 (최근 30일)
이전 댓글 표시
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
답변 (2개)
Thomas
2012년 7월 3일
편집: Thomas
2012년 7월 3일
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
Thomas
2012년 7월 3일
편집: Thomas
2012년 7월 3일
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
2012년 7월 3일
filenames = {'file1.txt', 'file2.txt', 'file3.txt'};
for K = 1 : length(filenames)
thisfile = filenames{K};
testfunction(thisfile)
end
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Characters and Strings에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!