How can i use linspace with different intervals?

조회 수: 3 (최근 30일)
Mahrosh
Mahrosh 2020년 5월 8일
댓글: Rik 2020년 5월 9일
The value for x is 0 to 1. I want to use 0 to 0.9 with interval 0.01 and 0.9 to 1 with interval 0.99.
I used linspcae like this but this is giving me an error.
x = linspace(0,0.9,91;0.9,1,91);
How can i use different interval in linspace? Any idea?

채택된 답변

Rik
Rik 2020년 5월 8일
You will have to call linspace multiple times:
part1=linspace(0,0.9,91);
part2=linspace(0.9,1,91);
x = [part1,part2(2:end)];
  댓글 수: 1
Mahrosh
Mahrosh 2020년 5월 8일
편집: Mahrosh 2020년 5월 8일
thanks for your comments.

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

추가 답변 (1개)

Steven Lord
Steven Lord 2020년 5월 8일
If you know both endpoints and the interval, linspace isn't the best tool for the job. The colon operator (:) is.
x = 0:0.1:0.9;
Rik's suggestion of creating each piece independently and combining them afterwards, but use colon instead of linspace.
  댓글 수: 5
Mahrosh
Mahrosh 2020년 5월 8일
Thankyou steven for further explanation. I want to ask there is any effect on my calculation If I used number in decimal instead of intergers?
Rik
Rik 2020년 5월 9일
There isn't any difference in the result, only in how you read the code as a human.

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

카테고리

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

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by