MATLAB Answers

0

Writing Code for function with CSV and character array

Asked by Lauren Kinchla on 14 Nov 2019 at 0:05
Latest activity Answered by Walter Roberson
on 14 Nov 2019 at 1:53
How do you code for a function that returns a character array associated with a column from a character array in comma-separated values (CSV) format.

  0 Comments

Sign in to comment.

Tags

No tags entered yet.

1 Answer

Answer by Walter Roberson
on 14 Nov 2019 at 1:53

If the column number to extract is C then
fmt = [repmat('%*s', 1, C-1), '%s', '%*[^\n]']
Now you can use that with textscan with Delimiter set to comma. You will need to convert the cell array that results into a character array.
There are other approaches including using readtable, especially after using detectImportOptions and setting the returned variables option to just the column you want.

  0 Comments

Sign in to comment.