How to extract a part of a given vector and store it in a new vector using loops (for loop) ?
43 次查看(过去 30 天)
显示 更早的评论
Given vector: [1 2 3 4 5 6 7 8 9 10];
New vector, let's say: [4 5 6 7].
2 个评论
Azzi Abdelmalek
2013-10-21
编辑:Azzi Abdelmalek
2013-10-21
Is it homework? If yes, what have you tried so far?
采纳的回答
sixwwwwww
2013-10-21
Dear Abhisek, here is the code for it:
a = [1 2 3 4 5 6 7 8 9 10];
indices_of_values2save = [4 5 6 7];
count = 1;
for i = 1:length(a)
if any(i == indices_of_values2save)
b(count) = a(i);
count = count + 1;
end
end
I hope it helps. Good luck!
更多回答(1 个)
Image Analyst
2013-10-21
编辑:Image Analyst
2013-10-21
data2 = data1(seg1:seg2); % Extract indexes seg1 through seg2 into new vector.
另请参阅
类别
在 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!