[Matlab] How to convert vector to string and save it to file

Status
Not open for further replies.

davyzhu

Advanced Member level 1
Joined
May 23, 2004
Messages
494
Helped
5
Reputation
10
Reaction score
2
Trophy points
1,298
Location
oriental
Activity points
4,436
matlab vector to string

Hi all,

I have a vector like vec=[1 0 1 0 1 0 0 1...].
How to convert it to string like str='10101001...'?
And how to save this string to a file?

Best regards,
Davy
 

vector to string matlab

vec = [1 0 1 0 1 0 0 1];
str = dec2hex(vec)';
fid = fopen('myfile', 'wt');
fprintf(fid, str);
fclose(fid);

You may also find the dlmwrite function useful.
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…