필터 지우기
필터 지우기

How to create a For loop for a linspace?

조회 수: 14 (최근 30일)
Michela Longhi
Michela Longhi 2017년 6월 28일
댓글: Star Strider 2017년 6월 28일
I have this code:
for j = 1:20
c(j) = linspace(1,10,length(j));
end
But, the result is a vector "c" with all the values "10":
c= 10 10 10 10 10 10 10....
How can I do to solve the problem? Thnaks

채택된 답변

Star Strider
Star Strider 2017년 6월 28일
Since in every iteration, ‘j’ is a scalar, the length of ‘j’ will always be 1.
I would just use:
c = linspace(1, 10, 20);
or if you actually want varying-length vectors, save ‘c’ as a cell array:
for j = 1:20
c{j} = linspace(1,10,j);
end
  댓글 수: 5
Michela Longhi
Michela Longhi 2017년 6월 28일
Yes!!!! It's now working. Thank you to all.
Star Strider
Star Strider 2017년 6월 28일
Our pleasure!

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Graphics Object Properties에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by