Meaning of s in string

조회 수: 3 (최근 30일)
S Weinberg
S Weinberg 2015년 2월 1일
댓글: S Weinberg 2015년 2월 2일
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]"

채택된 답변

Geoff Hayes
Geoff Hayes 2015년 2월 1일
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
S Weinberg
S Weinberg 2015년 2월 2일
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!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by