reading complex data into a matlab array

22 ビュー (過去 30 日間)
Alex
Alex 2011 年 11 月 27 日
回答済み: Matthew Parry 2019 年 11 月 7 日
Hi,
To keep it short: How can you read complex doubles into a matlab array from raw data files. To keep it long, see below.
I have a raw data file taken from an MR scanner. I have been using the IDL language to read/reconstruct it but my files have become large and the memory management in IDL is no longer good enough. I need to know how to read this data into matlab. The problem is in the data-type. IDL can create complex double arrays but it seems matlab cannot. The data is arranged as follows: header-->data-->header-->data... etc. I know how many bytes the headers are so i can move a pointer using fseek/fread etc however I do not know how to read in the data into an array. Each data point is a 16 byte complex number. If I dont move the pointers correctly then the data becomes scrambled etc. The data parts are structured: real --> IM --> real --> IM and so on. When I read in 16 bytes into IDL I get the correct values. It would be so simple if there were a complex double datatype in matlab. I've thought about parsing the data as I read it into a real and im matrix and then combining them afterwards but there must be an easier way?

採用された回答

Jared
Jared 2011 年 11 月 27 日
If I understand the question correctly, something along these lines should work (although don't trust me on the fread syntax - it's been a while):
fp = fopen(file_of_interest);
% code for reading the header, etc.
complex_matrix = complex(ones(final_size),ones(final_size));
for i=1:length(complex_matrix(:))
complex_matrix(i) = complex(fread(fp,8,'*double'),fread(fp,8,'*double'));
end
% whatever other finalization you need to do
fclose(fp);
  2 件のコメント
Alex
Alex 2011 年 11 月 27 日
Thanks Jared,
Ill try this out!
A
A 2012 年 2 月 7 日
What part of this solves the header->data->header->data?
I'm dealing with the same issue but not complex numbers. What exactly is the '8' in fread(fp,8,'*double") telling it to do? In that spot I currently have my matrix size [4x4]. Is there a way to not read in the header parts?

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

その他の回答 (1 件)

Matthew Parry
Matthew Parry 2019 年 11 月 7 日
From R2019a onwards you can use the function readmatrix().

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by