Error while using writematrix to save complex values in a .txt

Hello, I have a very basic script that reads in around 15000 complex values from a .csv file, does some basic data manipulation and saves it into a .txt file using writematrix. However, it seems the values with a negative imaginary component (i.e. in the form of a-bi) are being saved into the .txt as a+-bi. Calling a readmatrix on this file saves these values as NaN and I cannot proceed. Any ideas? A segment of the code follows along with the exported file values.
%% 1. .csv file to table to array
%% 2-4: Modify values by basic division, rss, etc
%% 5. Export data
writematrix(signal_d_prime, 'signal_modified.txt', 'Delimiter', ' ')
%% Check
readmatrix('signal_modified.txt')
signal mod.JPG

 採用された回答

Jeremy
Jeremy 2019 年 12 月 4 日
編集済み: Jeremy 2019 年 12 月 4 日

1 投票

csvwrite
Does this correctly. I will look into writematrix

4 件のコメント

Ragini Bakshi
Ragini Bakshi 2019 年 12 月 4 日
Thank you Jeremy, csvwrite does work for my purpose. Cheers!
Emanuel Gunnarsson
Emanuel Gunnarsson 2021 年 5 月 26 日
Hi Jeremy!
I have the same problem as Ragini, but csvwrite doesn't help me.
If I use csvwrite, more of the numbers will not become NaN but still most of them do.
I tried manually to alter the formatting of the data in Notepad ++; changing delimiter to '\t' and replaceing all '+-' with '-'. That helped readmatrix, but it would be rather tedious to do that to all of my files.
Unfortunatly it looks like one cannot specify such things with csvwrite.
Any suggestions?
Pax et bonum!
Emanuel
Jeremy
Jeremy 2021 年 5 月 26 日
編集済み: Jeremy 2021 年 5 月 26 日
What version of MATLAB are you using? The issue with writematrix described in this post was fixed in R2020b. If you are using an older version I would recommend updating. If you are using a recent version and still running into an issue I would recommend making a separate question post.
XYC
XYC 2022 年 1 月 9 日
Hello Jeremy, I have the same problem when I call writematrix to write the matrix into a txt file and I use R2021a, any solution to this?

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

その他の回答 (1 件)

Kristijan
Kristijan 2024 年 9 月 25 日

0 投票

I had the same problem with strange negitiated imaginary values. The writematrix function seems the work , but if you put an transpose a complex vector the imaginary part gets negotiated. The result is then saved with this reverted imaginary value. For example complex vector xvec. When u save the with writematrix(xvec',"matrix.txt") the stored values have negative complex entries.

1 件のコメント

marmite
marmite 2025 年 3 月 24 日
The single quotation mark operator actually does a conjugate transpose, so your observed behaviour is expected.

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

製品

リリース

R2019b

質問済み:

2019 年 12 月 4 日

コメント済み:

2025 年 3 月 24 日

Community Treasure Hunt

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

Start Hunting!

Translated by