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!

2 次查看(过去 30 天)
% 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);

回答(1 个)

Amrtanshu Raj
Amrtanshu Raj 2020-9-29
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

类别

Help CenterFile Exchange 中查找有关 Characters and Strings 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by