Info

此问题已关闭。 请重新打开它进行编辑或回答。

New with MatLab, need help

1 次查看(过去 30 天)
Thanh Cao
Thanh Cao 2018-4-10
关闭: MATLAB Answer Bot 2021-8-20
I have and 2 array. - First array contains one column of a string represent data and time like this
"20122906 092315"
- Second array contains three column of number like this
55.0529719779269 54.2662719394507 84.2787929148699
55.0485478536631 54.2647888297049 84.2789499779805
55.0470731369992 54.2633057156541 84.2853886145768
55.0441236908077 54.2588563476729 84.2858596439719
55.0396994893608 54.2558900808281 84.2798920353695
I want to print these to a text file with as follow:
20122906 092315;55.05;54.26;84.27CR&LF
20122906 092317;55.05;54.26;84.27CR&LF
20122906 092397;55.05;54.26;84.27CR&LF
.....
.....
.....
20122906 092397;55.05;54.26;84.27CR&LF
EOF

回答(1 个)

KSSV
KSSV 2018-4-10
str = {'20122906 092315'} ;
A = [55.0529719779269 54.2662719394507 84.2787929148699
55.0485478536631 54.2647888297049 84.2789499779805
55.0470731369992 54.2633057156541 84.2853886145768
55.0441236908077 54.2588563476729 84.2858596439719
55.0396994893608 54.2558900808281 84.2798920353695] ;
N = size(A,1) ;
str = repmat(str,N,1) ;
M = repmat(';',N,1) ;
S = repmat('CR&LF',N,1) ;
C = strcat(str,M,num2str(A(:,1)),M,num2str(A(:,2)),M,num2str(A(:,3)),S) ;
fid = fopen('data.txt','wt') ;
fprintf(fid,'%s\n',C{:}) ;
fclose(fid) ;

此问题已关闭。

标签

Community Treasure Hunt

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

Start Hunting!

Translated by