필터 지우기
필터 지우기

Creating an array of given size and increment

조회 수: 1,519 (최근 30일)
Adam
Adam 2014년 8월 19일
댓글: Steven Lord 2019년 6월 27일
This seems like a stupid question from someone with 8 years Matlab experience, but either I'm having a brain fade moment or there is no neat shortcut syntax to this.
I simply want to create an array with a known start, increment and number of elements.
Obviously if I have start, increment, end I can use the colon operator and if I have start, number of elements and end I can use linspace.
But is there really nothing neater than having to do the maths to work out the end point then use one of the above options? I'd rather just let the max be whatever it happens to be.
Calculating an explicit max in order to create a matrix with an implicit increment (using linspace) that should match exactly the increment I used to calculate the max seems very un-Matlab-like.
  댓글 수: 2
Efrem Ayichew
Efrem Ayichew 2019년 6월 27일
%0 to 200 in 10 increment
countInTen = linspace(0,20,21)*10 ;
Steven Lord
Steven Lord 2019년 6월 27일
A simpler way to count from 0 to 200 in increments of 10 is:
countByTens = 0:10:200;
In the original question, the user knew the starting point (0) and the increment (10) but couldn't use the colon operator because they knew how many fence rails they wanted to use (20 rails) or how many posts they wanted (21) rather than where they wanted their fence to end (200.)

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

채택된 답변

Rick Rosson
Rick Rosson 2014년 8월 19일
How about the following?
xStart = 5;
dx = 0.001;
N = 2000;
x = xStart + (0:N-1)*dx;
Is that what you are looking for?
  댓글 수: 5
Adam
Adam 2018년 9월 7일
What do you mean by 'roll over'? something like this?
xStart = 5;
dx = 1.5;
N = 2000;
x = mod( xStart + (0:N-1)*dx, 1024 );
Andrew Baker
Andrew Baker 2018년 9월 7일
Yes, I was using mod, but obviously in the wrong places, thanks for your help. I think I understand a little more how it's working now aswell.
Andrew

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

추가 답변 (1개)

Miysaa s
Miysaa s 2018년 11월 27일
Untitled.png

카테고리

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

제품

Community Treasure Hunt

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

Start Hunting!

Translated by