Meaning of s in string

3 visualizaciones (últimos 30 días)
S Weinberg
S Weinberg el 1 de Feb. de 2015
Comentada: S Weinberg el 2 de Feb. de 2015
Please help guys, thanks. My struggles involves around the question:
n=10;
fact=1;s
for k=1:n
fact=k*fact;
factorials(k,:)=[k fact];
end
factorials
I am using octave GNU. What does the "s" stand for in "fact=1;s". It makes no sense to me whatsoever. Also whats the difference in Matlab with the bracket () and [] as in "factorials(k,:)=[k fact]"

Respuesta aceptada

Geoff Hayes
Geoff Hayes el 1 de Feb. de 2015
S - I think that the s is a mistake and should not be there so just remove it. (It could have been a typo by the author of the code).
As for the use of (), in the context above the open brackets are used to access elements of the matrix factorials. In this case, on each iteration of the loop, we set all elements of the kth row to
[k fact]
which is just a two element array of k and fact. Here, the square brackets [] are used to concatenate the two scalar values into a 1x2 array.
  1 comentario
S Weinberg
S Weinberg el 2 de Feb. de 2015
Thanks! I think the s is also a mistake, but can be frustrating when the study guides do not explain thoroughly, and then there is a typo. After a late night last night i also kind of figured out the difference between the two brackets, but your answer makes it much clearer, thank you!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Programming en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by