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 Center および File ExchangeCharacters and Strings についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by