keeping elements of certain indices of an array
18 次查看(过去 30 天)
显示 更早的评论
I have a B column(Nx1) and i want to keep the elements of these indices: 11:2:41 and 45:4:101 and 111:10:401 and 441:40:801 and 901 and 1001.
So i want to 'extract' 73 elements of this B column to a new one D column, so that B(11)=D(1), B(13)=D(2),.....B(1001)=D(73).
As I've searched, matlab can't do looping with two parallel conditions, so I could write something like:
>>for i=11:2:41 and j=1:16
B(i)=D(j)
end...
So i have to connect i and j to one variable k, and loop for k..
The only idea i had is to write a BA table of 2 columns like this:
1 11
2 13
3 15
....
73 1001
an then write
>> for i=1:length(BA)
ba1=BA(i,1);ba2=BA(i,2) %%so that ba1=1 and ba2=11
B(ba2)=D(ba1) %%%so that B(11)=D(1)
end..
But this comes with this error: Undefined function 'D' for input arguments of type 'double'.
Also if i try to just erase elements with [], its getting very time consuming because if i want to keep indices e.g. 45,49,53 then i ll have to erase for 46:48,50:52, 54:56 etc....
Please help!! Thank you!
0 个评论
采纳的回答
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!