How to insert symbols in a vector in Matlab

I have a vector of 12 entities in Matlab. a=[3 4 6 8 1 5 8 9 3 7 3 6 ] I want to insert symbols at regular intervals along with the values. The final value of a looks like this. a=[#3 4@ 6& 8< #1 5@ 8& 9< #3 7@ 3& 6<] As can be seen that the symbols are being repeated after 3 entities. How can this be achieved in Matlab ?

1 Comment

You can do that as a string, but not in a numeric vector because obviously those elements are not numeric. If you have a vector of chars then it is trivial depending at what point you have the various information to create the end result.

Sign in to comment.

 Accepted Answer

a=[3 4 6 8 1 5 8 9 3 7 3 6 ]
str=strsplit(sprintf('#%d %d@ %d$ %d< ',a) )
str(end)=[]

2 Comments

@Azizi & @Star Strider. Thanks for the reply. Solutions suggested by both of you are OK. But can I get the solution without the '' (commas). How can I do it.

Sign in to comment.

More Answers (0)

Categories

Find more on Functions in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!