Ho to keep entries in a for loop
Afficher commentaires plus anciens
Hello hi i have a question how do i keep the entries in a for loop
Réponses (1)
Marc Jakobi
le 4 Oct 2016
You are pre-initializing ele with a zero, that's why it gets stored in ASCII in every loop iteration. I would change your code to the following:
nbr_elem = input('Enter the total number of elements in the molecule: ');
ele = [];
occ = zeros(1, nbr_elem) %it is good practise to pre-initialize arrays with their full size
for x = 1:nbr_elem
ele = [ele, input('Enter an element: ','s')];
occ(x) = input('Enter the element''s occurrence in the molecule: ');
end
Also, I would suggest using
while ~strcmp(ele(x), table_periodique(j(x),2))
in your while loop instead of ~= There is also no need to index j(x), you can just set j = 1. Hope this helps!
Catégories
En savoir plus sur Loops and Conditional Statements dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!