Writing code for function

2 visualizaciones (últimos 30 días)
Lauren Kinchla
Lauren Kinchla el 17 de Nov. de 2019
Respondida: Image Analyst el 17 de Nov. de 2019
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.

Respuestas (1)

Image Analyst
Image Analyst el 17 de Nov. de 2019
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);

Categorías

Más información sobre String Parsing en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by