Writing code for function

1 回表示 (過去 30 日間)
Lauren Kinchla
Lauren Kinchla 2019 年 11 月 17 日
回答済み: Image Analyst 2019 年 11 月 17 日
If one input is a character array in CSV, I need to write a function that will return 1 if an input of a character array is contained in the first input, and 0 if it is not.

回答 (1 件)

Image Analyst
Image Analyst 2019 年 11 月 17 日
Not sure what you want, and how this has to do with a CSV file, but there is already a built-in function "that will return 1 if an input of a character array" -- it is called ischar(). If you want, you can use fgetl() to call ischar() on every single line you read it.
% Open the file.
fileID = fopen(fullFileName, 'rt');
% Read the first line of the file.
textLine = fgetl(fileID);
while ischar(textLine)
% Print out what line we're operating on.
fprintf('%s\n', textLine);
if ischar(textLine(1))
% If first character of textLine is a character, do something.
end
% Read the next line.
textLine = fgetl(fileID);
end
% All done reading all lines, so close the file.
fclose(fileID);

カテゴリ

Help Center および File ExchangeString Parsing についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by