how convert txt file into excel file ?
조회 수: 4 (최근 30일)
이전 댓글 표시
Eg :
text file contains
kar_po_data_3_table.kar_po_data_3_basic.q2p_rc_m_ta_h3_cm_vc[0]=0.079387;
kar_po_data_3_table.kar_po_data_3_basic.p2e_rcs_m_ta_h3_cm_vc[1]=0.04785;
....
....
.....
final output : Excel file
kar_po_data_3_table kar_po_data_3_basic.q2p_rc_m_ta_h3_cm_vc[0] 0.03874
kar_po_data_3_basic.p2e_rcs_m_ta_h3_cm_vc[1] 0.04785
.... ...
.... ....
.... ....
.... .....
댓글 수: 0
답변 (1개)
Raunak Gupta
2019년 11월 21일
Hi,
Following Code might help write csv file in above format
text_file = fileread('test_text.txt');
content = regexp(text_file, ';', 'split');
content( cellfun(@isempty,content) ) = [];
table_to_write = cell2table(cell(size(content,2),3));
for i=1:size(content,2)
string_cell = content(1,i);
actual_string = string_cell{1};
first = regexp(actual_string, '=', 'split');
first( cellfun(@isempty,first) ) = [];
third_arg = char(first(1,2));
second = regexp(first{1}, '.', 'split');
second( cellfun(@isempty,second) ) = [];
first_arg = strtrim(second{1});
second_arg = strjoin(second(1,2:3),'\.');
table_to_write.Var1(i) = {first_arg};
table_to_write.Var2(i) = {second_arg};
table_to_write.Var3(i) = {third_arg};
end
writetable(table_to_write,'csvFile.csv','WriteVariableNames',false,'Delimiter',',');
For Reading the csv file again in MATLAB note that the delimiter must be 'comma'(',').
댓글 수: 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!