Concept Flow - String concatenation
Start with strings
Use concatenation operator
Combine strings into one
Store or display result
End
This flow shows how MATLAB takes separate strings and joins them into one string using concatenation.
str1 = 'Hello, '; str2 = 'world!'; result = [str1 str2]; disp(result);
| Step | Action | Variable | Value | Output |
|---|---|---|---|---|
| 1 | Assign string | str1 | 'Hello, ' | |
| 2 | Assign string | str2 | 'world!' | |
| 3 | Concatenate | result | 'Hello, world!' | |
| 4 | Display | result | 'Hello, world!' | Hello, world! |
| Variable | Start | After Step 1 | After Step 2 | After Step 3 | Final |
|---|---|---|---|---|---|
| str1 | undefined | 'Hello, ' | 'Hello, ' | 'Hello, ' | 'Hello, ' |
| str2 | undefined | undefined | 'world!' | 'world!' | 'world!' |
| result | undefined | undefined | undefined | 'Hello, world!' | 'Hello, world!' |
String concatenation in MATLAB: - Use square brackets [ ] to join strings. - Example: result = [str1 str2]; - Result is a new combined string. - Use disp(result) to show the string. - Forgetting brackets causes errors.