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