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 (최근 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에서 String Parsing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by