Read text file and store in .mat file

Assume i have the following values in a text file.
102
103
43.
i want to read this text file and store in a .mat file so that i can access the array of value.

 採用された回答

dpb
dpb 2013 年 8 月 24 日

3 投票

data=importdata('yourfile.txt');
Use the data as is...
doc save % and friends to write/read .mat files...
If the data in the text file contain more formatting, etc., than just the simplest, then
doc textscan % and friends
help iofun
will give a list of all the choices (a veritable plethora from which to choose depending on what you have as the input format).

4 件のコメント

Sudharsan
Sudharsan 2013 年 8 月 24 日
Thanks a lot for your reply. It works fine.
What if i use mixed data formats. (i.e)
16A
15E
0C
dpb
dpb 2013 年 8 月 24 日
編集済み: dpb 2016 年 12 月 28 日
Presuming it's actually hex as it appears, use one of the formatted input functions such as
doc textread
doc textscan
doc fscanf
and the hex format descriptor string '%x'
If you know anything about C, that's helpful as Matlab uses its notation and i/o based on the C library. If not, the formatting descriptors are described fully in the fscanf documentation.
shuchita bahadur
shuchita bahadur 2016 年 12 月 28 日
when usinf importdata in Command line it works, not from within a script. The variable does'nt show in workspace.
dpb
dpb 2016 年 12 月 28 日
In a script is the same as at the command line. If you mean a function m-file, yes, variables are local in scope within functions; to return the variable to the calling scope (command line or calling function), that function must have a return variable and the result of the read operation, whatever routine you use, returned to the caller via that variable.
See
doc function
for how functions work...

サインインしてコメントする。

その他の回答 (1 件)

dwarose
dwarose 2013 年 8 月 24 日

0 投票

etc., than just the simplest, then doc textscan % and friends help iofun will give a list of all the choices (a veritable plethora from which to choose depending on what you have as the input formatUse the data as is... doc save % and friends to write/read .mat files... If the data in the text file contain more formatting, http://justintv-fenerbahce-eskisehirspor-maci-canli-seyret.blogs.lalibre.be/

カテゴリ

ヘルプ センター および File ExchangeLarge Files and Big Data についてさらに検索

質問済み:

2013 年 8 月 24 日

コメント済み:

dpb
2016 年 12 月 28 日

Community Treasure Hunt

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

Start Hunting!

Translated by