필터 지우기
필터 지우기

Reading Table at fixed interval?

조회 수: 4 (최근 30일)
wesleynotwise
wesleynotwise 2017년 5월 23일
편집: wesleynotwise 2017년 5월 24일
For the following two commands
Table(1:10, :) %first
Table(1:2:10, :) %second
I know the first command will show the first 10 rows of data, and the second command will show the 1st, 3rd, 5th, 7th and 9th data.
I am wondering how useful the second command is? Can anyone explain?

채택된 답변

Jan
Jan 2017년 5월 24일
Using the indices 1:2:10 is very useful, if you need the indices 1,3,5,7,9. In all other cases it is not useful in any way.
Perhaps you want to set every 2nd value of a vector to 0:
x = rand(1, 100);
x(1:2:end) = 0;
Or maybe it is enough to plot every 10th element:
t = linspace(0, 2*pi, 10000);
x = sin(t);
plot(t(1:10:end), x(1:10:end))
The step width need not be an integer:
x = 0:0.1:1
There is an infinite number of applications of using the colon operator with 2 inputs. If you need a vector with a constant step size, it is perfectly useful. So what exactly is your question?
  댓글 수: 1
wesleynotwise
wesleynotwise 2017년 5월 24일
편집: wesleynotwise 2017년 5월 24일
Thanks for the clarification. Well, you can tell based on my question that I am fairly new to the Matlab. And, I thought that that feature is only meant for table reading, and didn't realise that it also applies to a simple vector! Ha.
Many thanks!

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

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by