combine between numbers and characters in one vector
Show older comments
i'm working on run length encoding, i use matlab and the input vector is
v=[ 1 2 2 2 2 5 -1 0 0 0 0 -2 -2 -2 -2 -2 7]
the output vector must be
w=[ 1 @ 2 4 5 -1 @ 0 4 @ -2 5 7]
@ is a character that indicates a repetition, then comes the repeated number and the number of repetition my question is : can i combine between characters and numbers in a same vector ?
1 Comment
"the output vector must be..."
That is not possible with MATLAB: a numeric array cannot hold a character like that.
"can i combine between characters and numbers in a same vector ?"
Not really, not in the way that you show. Numeric arrays can store character codes, but character codes are just numeric values, so they do not display differently from any other values. You will either have to use a numeric indicator, e.g. NaN, or change how you store your data.
Accepted Answer
More Answers (1)
You cannot mix actual numbers and strings in the same array, but you could store the numbers as strings, or use another identifier, such as NaN, and store everything as numbers. You could also mix numbers and strings in a cell array.
Best solution for you depends on how you want to process this output later.
Categories
Find more on Logical in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!