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.

답변 (1개)

Star Strider
Star Strider 2019년 1월 14일

0 개 추천

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

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 2019년 1월 14일
편집: Stephen23 2019년 1월 14일
@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.
Star Strider
Star Strider 2019년 1월 14일
@Stephen — Thank you. I was ‘away’ for the last few minutes, responding to another Question.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터 및 File Exchange에서 Large Files and Big Data에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by