How can I add a letter to a column of strings. For example i want all names in the column one to change to this Name T.

2 views (last 30 days)
I have one column with many names. I want to add a T to every name. How can I do that?

Accepted Answer

Walter Roberson
Walter Roberson on 6 Oct 2022
%build an example table
sourceletters = 'A':'P';
FirstColumn = string( sourceletters(randi(numel(sourceletters), 5, 7)));
T = table(FirstColumn)
T = 5×1 table
FirstColumn ___________ "MJKGICH" "CDHIOFN" "PKNLFOI" "LDOMKPF" "MNCMDKK"
%now do the work
T.TBefore = "T" + T.FirstColumn;
T.TAfter = T.FirstColumn + "T";
T
T = 5×3 table
FirstColumn TBefore TAfter ___________ __________ __________ "MJKGICH" "TMJKGICH" "MJKGICHT" "CDHIOFN" "TCDHIOFN" "CDHIOFNT" "PKNLFOI" "TPKNLFOI" "PKNLFOIT" "LDOMKPF" "TLDOMKPF" "LDOMKPFT" "MNCMDKK" "TMNCMDKK" "MNCMDKKT"
  4 Comments

Sign in to comment.

More Answers (0)

Categories

Find more on Cell Arrays in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by