Effacer les filtres
Effacer les filtres

How to Split array to sub arrays

4 vues (au cours des 30 derniers jours)
Chao Zhang
Chao Zhang le 8 Août 2021
Commenté : Chao Zhang le 8 Août 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.

Réponse acceptée

Matt J
Matt J le 8 Août 2021
Using mat2tiles (Download)
subarrays=mat2tiles(XY_P,[2,2])
  1 commentaire
Chao Zhang
Chao Zhang le 8 Août 2021
Great! Thanks a lot

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Characters and Strings dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by