Convert a Matrix to Struct ?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
I have a binary vector as [0 1 1 0 0 1 0 1]; I want convert it as one struct [01100101]; I want it to get the character thtat corresponding for it(I know that but I can not convert avector to struct).
thanks.
0 Kommentare
Akzeptierte Antwort
Jan
am 22 Sep. 2011
Please type doc struct in the command window to learn more about structs. "[01100101]" is not a struct.
If you want the CHAR vector (also called "string"):
a = [0 1 1 0 0 1 0 1]
s = sprintf('%d', a)
1 Kommentar
Weitere Antworten (1)
Grzegorz Knor
am 22 Sep. 2011
Why do you want to create a struct?
Maybe just remove the spaces?
a = [0 1 1 0 0 1 0 1];
b = regexprep(num2str(a),'\W','')
2 Kommentare
Jan
am 22 Sep. 2011
This would be faster: b = strrep(num2str(a), ' ', '')
But why insert the spaces by NUM2STR only to remove them immediately. You can look in the source of NUM2STR to find out, that it is calling SPRINTF, such that the overhead can be avoided by calling it directly.
Siehe auch
Kategorien
Mehr zu Structures finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!