How to Split array to sub arrays

3 次查看(过去 30 天)
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])

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Characters and Strings 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by