Problem 57829. Convert vector of strings to lower triangular matrix
Given a non-empty vector vec of strings, please put its elements into the lower triangular half of a square matrix M column-wise. The remaining elements of M, those not filled this way, should contain empty strings, "".
For example, given
seq = [ "a" "b" "c" ]
your code should return
M = [
"a" ""
"b" "c"
]
while for
seq = strsplit("I like wine, and I like cheese, I like the smell of a westerly breeze.")
it should return
M = [
"I" "" "" "" ""
"like" "like" "" "" ""
"wine," "cheese," "the" "" ""
"and" "I" "smell" "a" ""
"I" "like" "of" "westerly" "breeze."
]
The number of elements of vec is not restricted (other than being positive), BTW, so e.g.
seq = [ "a" "b" "c" "d" ]
should yield
M = [
"a" "" ""
"b" "d" ""
"c" "" ""
]
P.S. the test suite will not check for cheating, but please be a good sport.
Solution Stats
Problem Comments
Solution Comments
Show commentsProblem Recent Solvers8
Suggested Problems
-
Sort a list of complex numbers based on far they are from the origin.
5603 Solvers
-
Sum all integers from 1 to 2^n
14751 Solvers
-
Who knows the last digit of pi?
654 Solvers
-
1070 Solvers
-
Construct an index vector from two input vectors in vectorized fashion
380 Solvers
More from this Author13
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!