kalmanfans's Blog

模式识别 非线性预测 复杂网络 Following your heart

Matlab中fscanf的用法

kalmanfans posted @ 2012年6月27日 13:49 in Matlab , 27244 阅读

今天读一段程序,主要目的是从一个文件中读取数据,然后用这些数据来画图。

matlab中的fscanf的用法如下:

A=fscanf(fid,format)
[A, count]=fscanf(fid,format,size)
[A, count]=fscanf(fid,format,size)


个人感觉用的最多的是 这样的形式:

data = fscanf(fid,format,size);

期中data为读取内容的数组,他的大小由size决定。size是一个[m n]的向量,

m为行,n为列(注意,这里读取的顺序是按列优先排列的,不明白的话可以看

下面的例子),若n取inf表示读到文件末尾。fid为fopen打开文件的返回值,

format是格式化参数(像printf、scanf)。

举个小例子:

路径+文件名:d:\moon.txt

内容:13,1,3.4

   3,2.1,23

1,12,2

   4,5.4,6

现在为了读取moon中的数据存在一个数组里,可以用如下方法

fid=fopen('d:\moon.txt');

data_1 =fscanf(fid,'%f,%f,%f',[3,inf]) ;%这里得用单引号

data_2 =fscanf(fid,'%f,%f,%f',[2,inf])

data_3 =fscanf(fid,'%f,%f,%f',[2,2])

fclose(fid);

这时data_1, data_2, data_3分别是一个数组,其内容分别如下:

data_1

13 3 1 4

1 2.1 12 5.4

4 23 2 6

data_2

13 3.4 2.1 1 2 4

1 3 23 12 4,5 6

data_3

13 3.4
1 3

由此可见,读数据的时候,从多维数组的水平方向,一个一个读取,传递给新的数组时,从列方向优先。

Avatar_small
Emma 说:
2023年1月17日 11:17

Fscanf is used in MATLAB to read data from a file. It takes in the file name and the format of the data in the file as cbd benefits arguments. The format can be a string or a cell array of strings. The data is read into an array and returned.

Avatar_small
seo service UK 说:
2024年1月16日 10:23

I found so many interesting stuff in your blog especially its discussion. From the tons of comments on your articles, I guess I am not the only one having all the enjoyment here! keep up the good work...

Avatar_small
먹튀폴리스신고 说:
2024年2月15日 06:18

One present why galore businesses opt for postcards is because they are overmuch cheaper to be prefab and this can forbear a lot of expenses on the lengthened run. 

Avatar_small
온라인카지노 说:
2024年2月15日 06:39

Superb web site, many thanks for finding the time to create these posts, i enjoy looking through all of them!

Avatar_small
메이저토토 说:
2024年2月15日 07:22

I had attempt to advance your own article in to delicius all things considered it’s anything but a predicament utilizing your data destinations would you be able to please reverify the thought. much appreciated again

Avatar_small
토토사이트 说:
2024年2月15日 07:31

This is actually the kind of information I have been trying to find. I am really happy with the quality and presentation of the articles. Thanks for this amazing blog post this is very informative and helpful for us to keep updating. This post is very informative on this topic.

Avatar_small
메이저토토사이트 说:
2024年2月15日 07:32

This is my first time I visit here. I found so many engaging stuff in your blog, particularly its conversation. From the huge loads of remarks on your articles, I surmise I am by all account not the only one having all the recreation here! Keep doing awesome. 

Avatar_small
먹튀사이트조회 说:
2024年2月15日 07:32

it’s really nice and meanful. it’s really cool blog. Linking is very useful thing.you have really helped lots of people who visit blog and provide them usefull

Avatar_small
먹튀팀즈 说:
2024年2月15日 07:46

Your blogs further more each else volume is so entertaining further serviceable It appoints me befall retreat encore. I will instantly grab your rss feed to stay informed of any updates.

Avatar_small
먹튀검증사이트 说:
2024年2月15日 08:13

Your blogs further more each else volume is so entertaining further serviceable It appoints me befall retreat encore. I will instantly grab your rss feed to stay informed of any updates.

Avatar_small
ok토토먹튀검증 说:
2024年2月15日 08:13

This article was written by a real thinking writer without a doubt. I agree many of the with the solid points made by the writer. I’ll be back day in and day for further new updates.

Avatar_small
먹튀검증커뮤니티 说:
2024年2月15日 08:41

This article was written by a real thinking writer without a doubt. I agree many of the with the solid points made by the writer. I’ll be back day in and day for further new updates.

Avatar_small
메이저놀이터추천 说:
2024年2月15日 08:58

I must say, as a lot as I enjoyed reading what you had to say, I couldnt help but lose interest after a while. Its as if you had a good grasp to the subject matter, but you forgot to include your readers. Perhaps you should think about this from far more than one angle. Or maybe you shouldnt generalise so considerably. Its better if you think about what others may have to say instead of just heading for a gut reaction to the subject. Think about adjusting your own thought process and giving others who may read this the benefit of the doubt.

Avatar_small
라이브바카라 说:
2024年2月15日 09:16

Thanks a lot for enjoying this beauty article with me. I am appreciating it very much! Looking forward to another great article. Good luck to the author! 

Avatar_small
토토사이트 说:
2024年2月15日 10:44

You have lifted a basic offspring..Blesss for using..I would need to think about better most recent exchanges from this blog..preserve posting..

Avatar_small
토토디펜드 说:
2024年2月15日 10:46

The next time I learn a weblog, I hope that it doesnt disappoint me as much as this one. I imply, I do know it was my choice to learn, however I actually thought youd have something attention-grabbing to say. All I hear is a bunch of whining about something that you could possibly fix should you werent too busy looking for attention.

Avatar_small
사설토토 说:
2024年2月15日 10:56

Your blogs further more each else volume is so entertaining further serviceable It appoints me befall retreat encore. I will instantly grab your rss feed to stay informed of any updates.

Avatar_small
먹튀대피소 说:
2024年2月15日 10:57

Hey all, I recently identified your internet site each and every The major search engines tiny searching for just like sort of educative support furthermore kinds shed light on beholds unbelievably excellent i think.

Avatar_small
먹튀검증커뮤니티 说:
2024年2月15日 11:02

While i reputation I would in addition train tough created for your incorporate site would like While i embark on a lot of salubrious moreover retained up-to-date chaotic using your situation.

Avatar_small
먹튀마루 说:
2024年2月15日 11:51

You have lifted a basic offspring..Blesss for using..I would need to think about better most recent exchanges from this blog..preserve posting..

Avatar_small
토토커뮤니티 说:
2024年2月15日 11:52

You have lifted a basic offspring..Blesss for using..I would need to think about better most recent exchanges from this blog..preserve posting..

Avatar_small
먹튀검증업체 说:
2024年2月15日 11:52

You have lifted a basic offspring..Blesss for using..I would need to think about better most recent exchanges from this blog..preserve posting..

Avatar_small
온라인카지노순위 说:
2024年2月15日 11:57

Hmm… As i fully grasp weblogs having a linked problem, all the same as i do not ended pictures web page. As i added in from the piece that can help populars moreover i’ll quite possibly possibly be people specific primer.

Avatar_small
카지노세상 说:
2024年2月15日 11:57

When a blind man bears the standard pity those who follow…. Where ignorance is bliss ‘tis folly to be wise….

Avatar_small
우리카지노가입쿠폰 说:
2024年2月15日 12:08

They also need to be good communicators, as they will often need to explain their ideas to clients and contractors. In addition, interior designers should have a good understanding of how different materials and finishes can impact a space. 

Avatar_small
토토사이트종류 说:
2024年2月15日 12:09

That is the excellent mindset, nonetheless is just not help to make every sence whatsoever preaching about that mather. Virtually any method many thanks in addition to i had endeavor to promote your own article in to delicius nevertheless it is apparently a dilemma using your information sites can you please recheck the idea.

Avatar_small
메이저안전놀이터 说:
2024年2月15日 12:10

Hey all, I recently identified your internet site each and every The major search engines tiny searching for just like sort of educative support furthermore kinds shed light on beholds unbelievably excellent i think.

Avatar_small
토토하이 说:
2024年2月15日 12:41

I am jovial you take pride in what you write. It makes you stand way out from many other writers that can not push high-quality content like you.

Avatar_small
사설토토 说:
2024年2月15日 12:41

It’s probably just as easy or difficult to make money online through a blog as it is selling information products like yours. The key to BOTH is the ability to create a following/list of loyal listeners. That’s the hard part! 

Avatar_small
แทงบอลออนไลน์ 说:
2024年2月15日 12:42

Thank you again for all the knowledge you distribute,Good post. I was very interested in the article, it's quite inspiring I should admit. I like visiting you site since I always come across interesting articles like this one.Great Job, I greatly appreciate that.Do Keep sharing! Regards,

Avatar_small
우리카지노 说:
2024年2月15日 12:42

You made such an interesting piece to read, giving every subject enlightenment for us to gain knowledge. Thanks for sharing the such information with us to read this

Avatar_small
먹튀검증사이트 说:
2024年2月15日 12:43

Celie body wave, deep wave, curly hair, loose wave, wet wavy, kinky straight and more charming sexy hairstyles always keep accompany with you on the way to beauty.

Avatar_small
먹튀검증커뮤니티 说:
2024年2月15日 12:44

Good website! I truly love how it is easy on my eyes it is. I am wondering how I might be notified whenever a new post has been made. I have subscribed to your RSS which may do the trick?

Avatar_small
안전토토사이트 说:
2024年2月15日 13:56

One present why galore businesses opt for postcards is because they are overmuch cheaper to be prefab and this can forbear a lot of expenses on the lengthened run. 

Avatar_small
먹튀검증커뮤니티 说:
2024年2月15日 13:59

Superb web site, many thanks for finding the time to create these posts, i enjoy looking through all of them!

Avatar_small
메이저사이트 说:
2024年2月15日 14:02

it’s really nice and meanful. it’s really cool blog. Linking is very useful thing.you have really helped lots of people who visit blog and provide them usefull

Avatar_small
먹튀사이트 说:
2024年2月15日 14:06

This is my first time I visit here. I found so many engaging stuff in your blog, particularly its conversation. From the huge loads of remarks on your articles, I surmise I am by all account not the only one having all the recreation here! Keep doing awesome. 

Avatar_small
메이저사이트 说:
2024年2月15日 14:09

This is actually the kind of information I have been trying to find. I am really happy with the quality and presentation of the articles. Thanks for this amazing blog post this is very informative and helpful for us to keep updating. This post is very informative on this topic.


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter