Writing code for function

5 次查看(过去 30 天)
Lauren Kinchla
Lauren Kinchla 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 CenterFile Exchange 中查找有关 String Parsing 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by