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!
5 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
% 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 commentaires
Réponses (1)
Amrtanshu Raj
le 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 commentaires
Voir également
Catégories
En savoir plus sur Characters and Strings dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!