# Adding names to each row automatically

1 view (last 30 days)
DARLINGTON ETAJE on 28 Aug 2019
Commented: DARLINGTON ETAJE on 28 Aug 2019
Imagine this
A=[2;4;3;1;3;4;1;3];
B=[-1;3;-4;-2;8;-9;1;-5];
E=zeros(8,1);
% such that
for i=1:8
if B(i)<0
elseif B(i)>0
E(i)='Good';
end
end
D=[A B E];
How do I find D...I want to label each row in D bad or good based te value in B...negative are for Bad while positive are for Good

Adam Danz on 28 Aug 2019
Edited: Adam Danz on 28 Aug 2019
If you want to form a matrix at the end, you'll need to keep the variables as numeric where "good" equals 1 and "bad" equals 0. That offers other benefits during analysis, too.
E = B > 0;
D=[A B E];
If you'd rather use strings,
E = cell(size(B));
E(B>0) = {'Good'};
Then put it in a table
T = table(A,B,E);
##### 2 CommentsShow 1 older commentHide 1 older comment
DARLINGTON ETAJE on 28 Aug 2019
Don't worry...getting 0 is not allowed in this program

### Categories

Find more on Tables 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!