replace the data from int to char in the matrix 200x1

hi i need help in matlab i'm new this first time i used my problem is i have a matrix one culome have some number from 1 to 28 i have replace the number with word mean
1 to normal
2 to left
3 to right
and for all number
the table name heart

 Accepted Answer

I am sharing one example here, hope it helps
data=randi(3,[1,10]);
data_cell=table(data);
str_data={'Normal','Left','Right'};
% Just kee those strings as per number accordingly
str_name=cell(1,10);
for i=1:length(data)
str_name(i)=str_data(data(i));
end
T=table(data',table(str_name'))
Result:
T =
10×2 table
Var1 Var2
Var1
___ __________
1 {'Normal'}
3 {'Right' }
3 {'Right' }
3 {'Right' }
1 {'Normal'}
3 {'Right' }
2 {'Left' }
2 {'Left' }
2 {'Left' }
3 {'Right' }

7 Comments

thank you but i have problem my matrix name is ANNOTD have the number i wil replace and can but number 0 to replace
i write this to take number but is not work data=ANNOTD(3,[1,10]);
Did you read the documentation for the randi function? This was just to create some example data to show working code. You should replace it with your own data.
Did you do a basic Matlab tutorial? You may consider doing the Onramp tutorial (which is provided for free by Mathworks).
%create some sample data for illustration purposes
%comment this next line out for your actual use
ANNOTD = randi([0 3],[10, 1]);
%now that we have the data, do the work
heart = table(ANNOTD);
names = {'Gummi', 'Normal','Left','Right'};
heart.Word = categorical(heart.ANNOTD, 0:length(names)-1, names)
heart = 10x2 table
ANNOTD Word ______ ______ 3 Right 0 Gummi 1 Normal 1 Normal 2 Left 3 Right 0 Gummi 2 Left 3 Right 1 Normal
thank you so much but the randi make random number i need put my data ANNOTD to replace the ANNOTD have number
%comment this next line out for your actual use
heart = table(ANNOTD);
names = {'Gummi', 'Normal','Left','Right'};
heart.Word = categorical(heart.ANNOTD, 0:length(names)-1, names)
thank you so much it is work

Sign in to comment.

More Answers (0)

Categories

Find more on Live Scripts and Functions in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!