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

7 次查看(过去 30 天)
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
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 CenterFile Exchange 中查找有关 cell 配列 的更多信息

标签

尚未输入任何标签。

产品


版本

R14SP1

Community Treasure Hunt

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

Start Hunting!