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

7 ビュー (過去 30 日間)
MathWorks Support Team
MathWorks Support Team 2017 年 5 月 24 日
回答済み: MathWorks Support Team 2017 年 6 月 15 日
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)しか出力されていません。
実部と虚部のどちらも保存する方法を教えてください。

採用された回答

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

その他の回答 (0 件)

カテゴリ

Help Center および File Exchangecell 配列 についてさらに検索

タグ

タグが未入力です。

製品


リリース

R14SP1

Community Treasure Hunt

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

Start Hunting!