convert csv file and write to another .m file
古いコメントを表示
Hello,
I am having problem reading in this file to matlab.
Data = readtable('100Cr6.csv','NumHeaderlines',0,'DecimalSeparator',',');
FID = fopen('kf100CR6.m', 'w');
fwrite(FID, Data, 'char');
fclose(FID);
i use the following code but it does not run successfully?
every time showing an error message:
"Error using fwrite
Cannot write value: unsupported class table
Error in convertCSV (line 15)
fwrite(FID, Data, 'char');"
i want every data in double notation (like 1231.2354) format in a .m file. so that i can use these as columns or rows of matrix.
Does anyone have a solution to this?
Many thanks.
2 件のコメント
Walter Roberson
2020 年 7 月 6 日
you have columns that have three parts separated by semi-colon. If those are acting as decimal points then you have too many of them. If they are acting as group separation then you appear to be missing a decimal separation.
jonas
2020 年 7 月 6 日
採用された回答
その他の回答 (2 件)
jonas
2020 年 7 月 6 日
Error message says that table class is not supported. You can pass the content of the table or just read the data as a matrix directly. I would try
Data = readmatrix('100Cr6.csv','NumHeaderlines',1,'DecimalSeparator',',')
dlmwrite('filename.m', Data)
5 件のコメント
Arif Ahmed
2020 年 7 月 6 日
Walter Roberson
2020 年 7 月 6 日
Add the option
'delimiter', ';'
to the readtable call
Arif Ahmed
2020 年 7 月 6 日
Arif Ahmed
2020 年 7 月 6 日
jonas
2020 年 7 月 6 日
I am getting the expected output.
Data = readmatrix('100Cr6.csv','NumHeaderlines',1,'DecimalSeparator',',')
dlmwrite('kf100CR6.m', Data)
clear all
mdata = load('kf100CR6.m');
size(mdata)
ans =
1248 4
mdata = [log(mdata(:,1)) log(mdata(:,2)) mdata(:,2) mdata(:,3) log(mdata(:,4))];
size(mdata)
ans =
1248 5
Arif Ahmed
2020 年 7 月 6 日
編集済み: Walter Roberson
2020 年 7 月 6 日
カテゴリ
ヘルプ センター および File Exchange で Characters and Strings についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!