Matrix to string, filled with zeros
Show older comments
I have a question about transforming a matrix. I have a matrix that looks something like this:
A = [9998; 9999; 0; 1; 2; ...... 9997; 9998; 9999; 0; 1; 2]
I want to turn this matrix into a string which contains always 4 elements:
B = ['9998'; '9999'; '0000'; '0001'; '0002'; ..... '9997'; '9998'; '9999'; '0000'; '0001'; '0002']
Then I also want to create a matrix (preferably without a loop) that adds 1 every time the number jumps down from 9999 to 0:
C = [0; 0; 1; 1; 1; 1; 1; 1; ..... 1; 1; 1; 2; 2; 2]
Accepted Answer
More Answers (1)
B=compose('%.4d',A);
C=cumsum( A(2:end)==0 & A(1:end-1)==9999 );
Categories
Find more on Operators and Elementary Operations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!