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
0 个评论
采纳的回答
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)
0 个评论
更多回答(1 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!