creating Arrys from another big array
1 次查看(过去 30 天)
显示 更早的评论
Hi, I have an array A of the size 1X1000. and i have a vector of Index: index=[1 25 40 63 77 99 100]
is there any easy way in matlab to create such arrays:
Arr1=(A(index(1)): A(index(2)))
Arr2=(A(index(2)): A(index(3)))
Arr3=(A(index(3)): A(index(4)))
and so on...
采纳的回答
更多回答(1 个)
Guillaume
2015-7-7
Another option to Thorsten's answer:
indices = [1 25 40 63 77 99 100];
A = rand(1, 100);
B = arrayfun(@(s,e) A(s:e), indices(1:end-1), indices(2:end), 'UniformOutput', false);
Note that it while it is possible to create variable names on the fly as in your example. It's a very bad idea. Using a cell array as in our answers is much better.
0 个评论
另请参阅
类别
在 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!