필터 지우기
필터 지우기

replace array numbers in places that are not the indices of another array

조회 수: 1 (최근 30일)
Hello, I have array_1 looks like this: array_1=[4 7 22 44 13 4 1 9 6 0 5 77 45 12];
I have another array -> array_2=3:7;
I need to write a code such that the indices of array_1 which are represented in array_2 will stay as they are and all the others will replaced by zeroe so I can get:
array_1=[0 0 22 44 13 4 1 0 0 0 0 0 0 0];
Help please! Thanks

채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2014년 4월 10일
array_1=[4 7 22 44 13 4 1 9 6 0 5 77 45 12];
array_2=3:7
array_3=zeros(size(array_1))
array_3(array_2)=array_1(array_2)

추가 답변 (1개)

Alon
Alon 2014년 4월 10일
Amazing!

카테고리

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