Concatenate an unknown amount of strings to a master string.

3 views (last 30 days)
I am trying to figure out how to add multiple strings to a master string. I want the end result to be a long string of binary numbers so I can parse into a cell array.
addingString = 1001
addingString = 1011
addingString = 1101
addingString = 1111
addingString = 1001
addingString = 0011
addingString = 1000
.
.
.
At the end of the loop the finalString should have all the contents inside:
finalString = 1001101111011111100100111000...
I tried different variations of concatenating strings/arrays and preallocated the size but nothing seemed to work.
Here is an excerpt of code:
while (data >= info)
finalString = [];
finalString = strcat(finalString, AddingString)
end
finalString
  2 Comments
James Tursa
James Tursa on 20 Mar 2018
Edited: James Tursa on 20 Mar 2018
What are the variable types? Is addingString a string, a char vector, a double? What you show above is a double, but it is not clear if this is actually what you have in your real code.

Sign in to comment.

Accepted Answer

David Fletcher
David Fletcher on 20 Mar 2018
Edited: David Fletcher on 20 Mar 2018
The first thing you are doing in your while loop is setting the finalString to [] - so you lose everything you concatenate together on every loop iteration. finalString=[] needs to be set before you enter the loop.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!