MATLAB で 複素数(complex) のデータを Excel ファイルに出力するにはどうすればよいですか?
7 views (last 30 days)
Show older comments
MathWorks Support Team
on 24 May 2017
Answered: MathWorks Support Team
on 15 Jun 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)しか出力されていません。
実部と虚部のどちらも保存する方法を教えてください。
Accepted Answer
MathWorks Support Team
on 24 May 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 スプレッド形式として保存
0 Comments
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!