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 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