How to extract consecutive numbers from array of integer numbers?

1 回表示 (過去 30 日間)
Giuseppe
Giuseppe 2022 年 5 月 9 日
回答済み: KSSV 2022 年 5 月 9 日
Hi guys,
I have an array of 40000 elements (attached to this question) that contains 20 consecutive groups of integer numbers from 1 to 200:
[1,2,3,4,5,...200,1,2,3,4,5,...200,1...]. Each group contains the indices that identify the points of an orbit, hence I have a database of 200 orbits.
I want to store these orbits in a variable (let's assume variable name is "orbits") so that I can associate to each orbit an integer number, for example to first 200 elements I want to associate the number 1 (orbit1---> 1:200), then to number 2 I want to associate the indices (integer numbers) from 201 to 400, and so on.
So, by following this line of reasoning, the indices of orbit no.9 go from 1801 to 2000.
As final result, by considering the orbit no.9 and by using the struct arrays, I'd like to get something like this:
orbit(1).idx = [1:200]
orbit(2).idx = [1801:2000]
.
.
.
orbit(9).idx = [1801:2000]
Can you help me to code this problem?

採用された回答

KSSV
KSSV 2022 年 5 月 9 日
Read about reshape
load('array.mat')
orbit = reshape(array,[],length(array)/200) ;

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeData Type Conversion についてさらに検索

製品


リリース

R2022a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by