loop for species names
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Michal Sleszynski
el 21 de Nov. de 2021
Comentada: Star Strider
el 21 de Nov. de 2021
So i need to use a for loop to generate the name of the species.
i would need to use CnH2n+2 for n:1 to 5 and the output should be in form below as i dont need variable names here i need a string
'CH4' , 'C2H6' and so on until C5H12'
it would be preferable that it is an array so that i can access those names by indexing
0 comentarios
Respuesta aceptada
Star Strider
el 21 de Nov. de 2021
Try this —
Species = @(n) strrep(compose('C%dH%d', [n(:) 2*n(:)+2]), '1H','H');
Hydrocarbon = Species(1:5)
Back to my undergraduate organic chemistry days ...
.
2 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Loops and Conditional Statements en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!