Filter löschen
Filter löschen

How to Split array to sub arrays

4 Ansichten (letzte 30 Tage)
Chao Zhang
Chao Zhang am 8 Aug. 2021
Kommentiert: Chao Zhang am 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.

Akzeptierte Antwort

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

Weitere Antworten (0)

Kategorien

Mehr zu Characters and Strings finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by