filename = 'Temp1.csv'
fileid = fopen(filename);
C = textscan(fileid,'%s',32,'%f',32,'delimiter',';');
Error using textscan
Unknown option '%f'
Why is this giving me such an error? %f is one of the formatspec in textscan. Then why is it giving me such an error.

Answers (1)

I have no idea what you want to do.
Perhaps this:
C = textscan(fileid, '%s %f ', 'delimiter',';');
I added a space for each ‘32’ (the ASCII numerical code for a space), since I assume you intend that.

3 Comments

The format of textscan
textscan(fileid, formatspec,N).
N is the number of times formatspec is applied. So I want %s 32 times, which is the heading, then %f 32 times which are the values. So that is what I intended to do. If I dont use %f and I just tried to read the 32 headings I am getting it correctly. I am getting the 32 headings. But when I add %f to the code, it is showing an error. N must be a positive integer. So space is not correct.
Stephen23
Stephen23 on 14 Jan 2019
Edited: Stephen23 on 14 Jan 2019
@Govind Sankar Madhavan Pillai Ramachandran Nair: neither the formatspec nor the N repeat. They each occur only once (N is optional), e.g.:
textscan(fileid, '%f%f%f', 4)
The format spec is usually written to match one whole line of the data file, while N is usually used to control how many lines of data are imported.
I suggest that you look at some of the documentation examples of how to use textscan, in particular taking a good look at examples of the format spec. You will find many examples just under the title Examples. Read them carefully.
@Stephen — Thank you. I was ‘away’ for the last few minutes, responding to another Question.

Sign in to comment.

Categories

Tags

Community Treasure Hunt

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

Start Hunting!