How to write a mixed data (number and {real, imag}) in a CSV file ?
1 次查看(过去 30 天)
显示 更早的评论
I need to write a CSV file with matrix in the first column and {real, imag} in the second column.
Example
matrix1 = {10;20;30};
matrix2 = [ { 2.3027900000000e-03, 2.0292300000000e-11};{ 8.6489600000000e-03, 1.7520000000000e-03};{ 8.5228400000000e-03, 7.1978700000000e-04}];
CSV file output as:
10 { 2.3027900000000e-03, 2.0292300000000e-11}
20 { 8.6489600000000e-03, 1.7520000000000e-03}
30 { 8.5228400000000e-03, 7.1978700000000e-04}
The second is real and imag value in curly brackets with a comma. I need this format to replace the data in a pyhond code.
Thanks!
0 个评论
采纳的回答
Voss
2022-12-6
Does this work for you?
matrix1 = {10;20;30};
matrix2 = [ { 2.3027900000000e-03, 2.0292300000000e-11};{ 8.6489600000000e-03, 1.7520000000000e-03};{ 8.5228400000000e-03, 7.1978700000000e-04}];
C = [matrix1 compose('{%e, %e}',reshape([matrix2{:}],size(matrix2)))];
writecell(C,'csv_file.csv')
If not, please upload a sample csv file that has the required format.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Spreadsheets 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!