How can I add a column with labelining in a matrix

1 view (last 30 days)
I have data matrix. I have to add label column with same name Before in the matrix. How I can add this labeling?

Accepted Answer

Chunru
Chunru on 27 Aug 2021
% Create a table with some data
a = (1:10)'; b=rand(10, 1); c=randi([1,100], 10, 1);
T = table(a, b, c)
T = 10×3 table
a b c __ _______ __ 1 0.31924 57 2 0.41572 9 3 0.33329 31 4 0.52433 42 5 0.60832 6 6 0.56471 1 7 0.19825 51 8 0.20861 67 9 0.75822 19 10 0.8956 96
% Now add the label
T.label = repmat("Before", 10, 1);
T = T(:, [end 1:end-1])
T = 10×4 table
label a b c ________ __ _______ __ "Before" 1 0.31924 57 "Before" 2 0.41572 9 "Before" 3 0.33329 31 "Before" 4 0.52433 42 "Before" 5 0.60832 6 "Before" 6 0.56471 1 "Before" 7 0.19825 51 "Before" 8 0.20861 67 "Before" 9 0.75822 19 "Before" 10 0.8956 96
  1 Comment
Sazid Hasan
Sazid Hasan on 27 Aug 2021
Thank you very much. If I split label like before and after 5 for before and 5 for after how it will be done? As i try define the size, it not working.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!