フィルターのクリア

Read data form file

3 ビュー (過去 30 日間)
Berbia
Berbia 2013 年 1 月 10 日
I'm trying to read values from the file and store it as a matrix.In the file there is two line space between each matrix values, and each should store as separate matrix. suppose my file has the content,
File vector.mat
1.1 2.2 3.3 4.4 5.5
2.2 3.3 4.4 5.5 6.6
3.3 4.4 5.5 6.6 7.7
6.6 7.7 8.8 9.9 9.9
7.7 8.8 9.9 1.1 2.2
8.8 9.9 1.1 2.2 3.3
I want to read these values and stored as two matrix
A= [1.1 2.2 3.3 4.4 5.5
2.2 3.3 4.4 5.5 6.6
3.3 4.4 5.5 6.6 7.7]
and
B= [6.6 7.7 8.8 9.9 9.9
7.7 8.8 9.9 1.1 2.2
8.8 9.9 1.1 2.2 3.3]
Can any one give idea to implement this in matlab? Thanks in advance.....
  2 件のコメント
per isakson
per isakson 2013 年 1 月 10 日
... two line space between ... is that two empty lines (or lines with only space)?
Do all "matrices" have the same number of columns?
Berbia
Berbia 2013 年 1 月 10 日
Two empty lines between each matrix and all matrices have same number of columns but number of rows vary.

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

採用された回答

per isakson
per isakson 2013 年 1 月 10 日
編集済み: per isakson 2013 年 1 月 10 日
See TEXTSCAN Reading After a specified term(or a row) and writing matrix. That includes the solution (including code) to a similar problem.
The basic approach is
  1. read the complete file and store each row as one string
  2. find the positions of the empty rows and calculate the size of the blocks
  3. read the file a second time with the proper format specifier
fid = fopen(...)
loop over all blocks
fgetl( ) % read the empty lines
cac = textscan( format, block_size, ... );
end
Do not worry about the time it takes to read the file a second time. If it is not huge it is red from the cache the second time.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeText Files についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by