Clear Filters
Clear Filters

How to Split array to sub arrays

4 views (last 30 days)
Chao Zhang
Chao Zhang on 8 Aug 2021
Commented: Chao Zhang on 8 Aug 2021
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.

Accepted Answer

Matt J
Matt J on 8 Aug 2021
Using mat2tiles (Download)
subarrays=mat2tiles(XY_P,[2,2])

More Answers (0)

Categories

Find more on Characters and Strings in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!