MATLAB で 複素数(complex) のデータを Excel ファイルに出力するにはどうすればよいですか?

7 visualizzazioni (ultimi 30 giorni)
MathWorks Support Team
MathWorks Support Team il 24 Mag 2017
xlswrite 関数で、複素数の行列を Excel ファイルとして保存しようと以下のコマンドを実行しました。
 
% create matrix of complex numbers
z = [2+3i 4+5i; 18+9i 1+17i];
% write the contents of the cell array to the Excel file
xlswrite('testfile',z)
しかし、作成された Excel ファイルを開きてみると、複素数の実部(real part)しか出力されていません。
実部と虚部のどちらも保存する方法を教えてください。

Risposta accettata

MathWorks Support Team
MathWorks Support Team il 24 Mag 2017
xlswrite 関数では、複素数のデータを出力することができません。
回避方法として、複素数の値を文字列として出力します。
以下の例では、複素数の数値データをセル配列に変換後、さらに文字列へ変換します。
 
z = [2+3i 4+5i; 18+9i 1+17i];
c = num2cell(z); % セル配列に変換
towrite = cellfun(@num2str , c, 'UniformOutput', false); % 各要素を文字列に変換
xlswrite('testfile_new',towrite) % Excel スプレッド形式として保存

Più risposte (0)

Categorie

Scopri di più su cell 配列 in Help Center e File Exchange

Tag

Non è stata ancora inserito alcun tag.

Prodotti


Release

R14SP1

Community Treasure Hunt

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

Start Hunting!