MATLAB Answers

# Hello! I am trying to append an element into a 5x5 empty cell called 'punnettSquare'. How can I append the first element of a1 and the first element b1 into row 2 column 1 of punnettSquare? Thank you!

1 view (last 30 days)
Lavitania Searjaya on 24 Sep 2020
Answered: Amrtanshu Raj on 29 Sep 2020
% For error checking
valid_inputA = {'AA';'Aa';'aa'};
valid_inputB = {'BB';'Bb';'bb'};
% Asking the user for input
parentOneA = input('Enter Parent 1 A Trait: ', 's');
% Error checking input
while ~any(strcmp(parentOneA, valid_inputA))
parentOneA = input('Your input is invalid. Please enter parent 1 A trait: ', 's');
end
parentOneB = input('Enter Parent 1 B Trait: ', 's');
% Error checking input
while ~any(strcmp(parentOneB, valid_inputB))
parentOneB = input('Your input is invalid. Please enter parent 1 B trait: ', 's');
end
parentTwoA = input('Enter Parent 2 A Trait: ', 's');
% Error checking input
while ~any(strcmp(parentTwoA, valid_inputA))
parentTwoA = input('Your input is invalid. Please enter parent 2 A trait: ', 's');
end
parentTwoB = input('Enter Parent 2 B Trait: ', 's');
% Error checking input
while ~any(strcmp(parentTwoB, valid_inputB))
parentTwoB = input('Your input is invalid. Please enter parent 2 B trait: ', 's');
end
row = 5; col = 5;
punnettSquare = cell(row,col)
a1 = num2cell(parentOneA);
b1 = num2cell(parentOneB);
a2 = num2cell(parentTwoA);
b2 = num2cell(parentTwoB);

#### 0 Comments

Sign in to comment.

### Answers (1)

Amrtanshu Raj on 29 Sep 2020
Hi,
Adding this line to the end of the code will get you the desired results.
punnettSquare{2,1}={a1{1},b1{1}}; % if you want them as a cell
punnettSquare{2,1}=[a1{1},b1{1}]; % if you want them as a string

#### 0 Comments

Sign in to comment.

### Community Treasure Hunt

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

Start Hunting!