How to Split array to sub arrays

3 ビュー (過去 30 日間)
Chao Zhang
Chao Zhang 2021 年 8 月 8 日
コメント済み: Chao Zhang 2021 年 8 月 8 日
Hi, I have a question about how to split the initial array to sub arrays
%Introduce the endpoints of dividing lines(from left to right)
nlines = num - 1;%num of dividing lines
%X-coord of endpoints(every dividing line has two X-coord of endpoints)
px_title = 'Input X coordinates of endpoints of each dividing line';
px_str = compose("X%d", 1 : 2*nlines);
str_px = inputdlg(px_str, px_title, [1,length(px_title)+50]);
px_coord = str2double(str_px);
%Y-coord of endpoints(every dividing line has two Y-coord of endpoints)
py_title = 'Input Y coordinates of endpoints of each dividing line';
py_str = compose("Y%d", 1 : 2*nlines);
str_py = inputdlg(py_str, py_title, [1,length(py_title)+50]);
py_coord = str2double(str_py);
%Assign X,Y points to XY_P array
XY_P = zeros(2*nlines,2);
%Execution loop
for q = 1 : 2*nlines
XY_P(q,1) = px_coord(q,:);
XY_P(q,2) = py_coord(q,:);
end
x coord and y coord make up an initial array XY_P, and I want to split this into sub array
for example, the follow is the XY_P, and red, blue and black boxes are presented array1, array2 and array3 respectively, so how to achieve it? I used reshape before, but it seems not correct.

採用された回答

Matt J
Matt J 2021 年 8 月 8 日
Using mat2tiles (Download)
subarrays=mat2tiles(XY_P,[2,2])
  1 件のコメント
Chao Zhang
Chao Zhang 2021 年 8 月 8 日
Great! Thanks a lot

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by