How to read file with complex number as well as real numbers

1 回表示 (過去 30 日間)
Nidhi SRIVASTAVA
Nidhi SRIVASTAVA 2017 年 7 月 4 日
コメント済み: Nidhi SRIVASTAVA 2017 年 7 月 4 日
I have a huge file with first real numbers and then complex numbers(file attached). I want to read the file and store the real numbers as variable frequency , first 5 rows of complex numbers as unit_1 and remaining as unit_2. Kindly help. Thanks.

採用された回答

per isakson
per isakson 2017 年 7 月 4 日
編集済み: per isakson 2017 年 7 月 4 日
If "huge" is a fraction of the size of the memory:
str = fileread( 'try_file.txt' );
ixc = find( str=='(', 1, 'first' );
cac = textscan( str(1:ixc-1), '%f%f%f%f%f%f', 'CollectOutput',true );
num = cac{1};
cac = textscan( str(ixc:end), '%f%f%f%f', 'CollectOutput',true ...
, 'Delimiter',{'(',')',','}, 'MultipleDelimsAsOne',true );
z = complex( cac{1}(:,[1,3]), cac{1}(:,[2,4]) );
and inspect the results
>> whos num z
Name Size Bytes Class Attributes
num 13x6 624 double
z 11x2 352 double complex
>> num(1,:)
ans =
97.0210 97.0600 97.0990 97.1380 97.1770 97.2160
>> z(1,:)
ans =
0.1818 + 0.0572i 0.0274 + 0.4233i
>>
  1 件のコメント
Nidhi SRIVASTAVA
Nidhi SRIVASTAVA 2017 年 7 月 4 日
Thanks a lot for the prompt answer. It pacifies to my requirement.

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

その他の回答 (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