0
MATLAB의 구조에 약간 문제가 있습니다. 나는 내 자신의 작은 주기율표를 만들어야하고 나는 지금까지 잘 끝냈다 고 생각한다. 하지만 내 문제는 내가 첫 번째 요소 위에 쓴 두 번째 요소를 추가하려고 할 때이다. 이 문제를 어떻게 해결할 수 있습니까? 제 코드를 살펴 보시기 바랍니다. 조금 길었습니다. D 다른 실수가 있으면 감사하겠습니다. 도움을 주셔서 감사합니다matlab, 구조, 주기율표 작성
fprintf('Periodic table program - Main menu:\n (1) Add an element; (2) Search for an element; (3) Exit\n');
choose=input('Enter your choice: ');
while choose~=3
if choose==1
element.name=input('Enter the name of your element: ','s');
element.symbol=input('Enter the symbol of your element: ','s');
element.Anumber=input('Enter the atomic number of your element: ');
while element.Anumber<=0 || mod(element.Anumber,1)~=0
disp('This is not a positive integer, please enter a valid input!');
eAnumber=input('Enter the atomic number of your element: ');
end
elseif choose==2
fprintf('Search menu:\n (1) By name; (2) By symbol; (3) By atomic number; (4) Main menu\n');
S_choice=input('Enter your choice: ');
while S_choice ~=4
if S_choice==1
alex=input('Enter the name of the element: ','s');
if alex~=element.name
disp('No such element exists!');
else
fprintf('Operations menu:\n (1) Show properties; (2) Edit; (3) Main menu\n');
Op_choice=input('Enter your choice: ');
while Op_choice~=3
if Op_choice==1
element
elseif Op_choice==2
fprintf('Edit menu:\n (1) Edit name; (2) Edit symbol; (3) Edit atomic number; (4) Main menu\n');
E_choice=input('Enter your choice: ');
while E_choice~=4
if E_choice==1
new_name=input('Enter the new name of the element: ','s');
element.name=new_name;
elseif E_choice==2
new_sym=input('Enter the new symbol of the element: ','s');
element.symbol=new_sym;
elseif E_choice==3
new_anumber=input('Enter the new atomic number: ');
while new_anumber<=0 || mod(new_anumber,1)~=0
disp('This is not a positive integer, please enter a valid input!');
new_anumber=input('Enter the new atomic number: ');
end
element.Anumber=new_anumber;
end
fprintf('Edit menu:\n (1) Edit name; (2) Edit symbol; (3) Edit atomic number; (4) Main menu\n');
E_choice=input('Enter your choice: ');
end
end
fprintf('Operations menu:\n (1) Show properties; (2) Edit; (3) Main menu\n');
Op_choice=input('Enter your choice: ');
end
end
elseif S_choice==2
lugano=input('Enter the symbol of the element: ','s');
if lugano~=element.symbol
disp('No such element exists!');
else
fprintf('Operations menu:\n (1) Show properties; (2) Edit; (3) Main menu\n');
Op_choice=input('Enter your choice: ');
while Op_choice~=3
if Op_choice==1
element
elseif Op_choice==2
fprintf('Edit menu:\n (1) Edit name; (2) Edit symbol; (3) Edit atomic number; (4) Main menu\n');
E_choice=input('Enter your choice: ');
while E_choice~=4
if E_choice==1
new_name=input('Enter the new name of the element: ','s');
element.name=new_name;
elseif E_choice==2
new_sym=input('Enter the new symbol of the element: ','s');
element.symbol=new_sym;
elseif E_choice==3
new_anumber=input('Enter the new atomic number: ');
while new_anumber<=0 || mod(new_anumber,1)~=0
disp('This is not a positive integer, please enter a valid input!');
new_anumber=input('Enter the new atomic number: ');
end
element.Anumber=new_anumber;
end
fprintf('Edit menu:\n (1) Edit name; (2) Edit symbol; (3) Edit atomic number; (4) Main menu\n');
E_choice=input('Enter your choice: ');
end
end
fprintf('Operations menu:\n (1) Show properties; (2) Edit; (3) Main menu\n');
Op_choice=input('Enter your choice: ');
end
end
elseif S_choice==3
niang=input('Enter the atomic number of the element: ');
if niang~=element.Anumber
disp('No such element exists!');
else
fprintf('Operations menu:\n (1) Show properties; (2) Edit; (3) Main menu\n');
Op_choice=input('Enter your choice: ');
while Op_choice~=3
if Op_choice==1
element
elseif Op_choice==2
fprintf('Edit menu:\n (1) Edit name; (2) Edit symbol; (3) Edit atomic number; (4) Main menu\n');
E_choice=input('Enter your choice: ');
while E_choice~=3
if E_choice==1
new_name=input('Enter the new name of the element: ','s');
element.name=new_name;
elseif E_choice==2
new_sym=input('Enter the new symbol of the element: ','s');
element.symbol=new_sym;
elseif E_choice==3
new_anumber=input('Enter the new atomic number: ');
while new_anumber<=0 || mod(new_anumber,1)~=0
disp('This is not a positive integer, please enter a valid input!');
new_anumber=input('Enter the new atomic number: ');
end
element.Anumber=new_anumber;
end
fprintf('Edit menu:\n (1) Edit name; (2) Edit symbol; (3) Edit atomic number; (4) Main menu\n');
E_choice=input('Enter your choice: ');
end
end
fprintf('Operations menu:\n (1) Show properties; (2) Edit; (3) Main menu\n');
Op_choice=input('Enter your choice: ');
end
end
end
fprintf('Search menu:\n (1) By name; (2) By symbol; (3) By atomic number; (4) Main menu\n');
S_choice=input('Enter your choice: ');
end
end
fprintf('Periodic table program - Main menu:\n (1) Add an element; (2) Search for an element; (3) Exit\n');
choose=input('Enter your choice: ');
end
나는 셀 배열에 넣을 수 있지만 1x1 구조 형태입니다. –
구조체 형태로 액세스해야하는데 알아낼 수 없습니다. ( –