필터 지우기
필터 지우기

How can I remove the ranges from a specific column vector?

조회 수: 1 (최근 30일)
Tuncay Eren
Tuncay Eren 2018년 3월 28일
댓글: David Fletcher 2018년 3월 28일
Hello;
How can I remove the following ranges from the k column vector below:
k=[1 0 2 1 9 8 0 0 4 2 3 3 5 1 1 0 3 2].' ;
ranges to be removed from k column vector are as;
range1=k(1:4); range1=k(9:12); range1=k(13:16);
Thanks in advance!!

채택된 답변

Stephen23
Stephen23 2018년 3월 28일
편집: Stephen23 2018년 3월 28일
>> vec = [1;0;2;1;9;8;0;0;4;2;3;3;5;1;1;0;3;2;0;0;0;0;0;0];
>> tmp = reshape(vec,12,[])
tmp =
1 5
0 1
2 1
1 0
9 3
8 2
0 0
0 0
4 0
2 0
3 0
3 0
>> tmp(1:4,:) = []
tmp =
9 3
8 2
0 0
0 0
4 0
2 0
3 0
3 0
>> tmp(:)
ans =
9
8
0
0
4
2
3
3
3
2
0
0
0
0
0
0
  댓글 수: 2
David Fletcher
David Fletcher 2018년 3월 28일
Neat. Easily beats my solution.
a=1:4
b=0:12:N;
c=a+repmat(b,4,1)';
del=reshape(c',1,numel(c))
k(del)=[]
Tuncay Eren
Tuncay Eren 2018년 3월 29일

Superb! Many thanks Stephan, David.

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

추가 답변 (1개)

David Fletcher
David Fletcher 2018년 3월 28일
del=[1:4 9:12 13:16]
k(del)=[]
  댓글 수: 1
Tuncay Eren
Tuncay Eren 2018년 3월 28일
Thanks David.
İf k is a data vector as 1024x1, then how can we make it as a general formula to remove consecutive 4 bits and then keep 8 consecutive bits, then again remove 4 bits and keep 8 bits...
N=1024;
k=randi([0 1],N,1);
k_remove1=k(1:4);
k_remove2=k(13:16);
k_remove3=k(25:28);
.
.
.
Thanks

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

카테고리

Help CenterFile Exchange에서 Workspace Variables and MAT-Files에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by