Meaning of s in string

4 views (last 30 days)
S Weinberg
S Weinberg on 1 Feb 2015
Commented: S Weinberg on 2 Feb 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]"

Accepted Answer

Geoff Hayes
Geoff Hayes on 1 Feb 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 Comment
S Weinberg
S Weinberg on 2 Feb 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!

Sign in to comment.

More Answers (0)

Categories

Find more on Programming in Help Center and File Exchange

Tags

Products

Community Treasure Hunt

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

Start Hunting!