Info

This question is closed. Reopen it to edit or answer.

New with MatLab, need help

1 view (last 30 days)
Thanh Cao
Thanh Cao on 10 Apr 2018
Closed: MATLAB Answer Bot on 20 Aug 2021
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

Answers (1)

KSSV
KSSV on 10 Apr 2018
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!