Split array into pieces according to corresponding array - MATLAB Cody - MATLAB Central

Problem 2953. Split array into pieces according to corresponding array

Difficulty:Rate

An array x of length n has values 1...m with each value appearing at least once. The values are sorted (n>=m).

A second array y of the same size should be split into elements of a cell array c such that the first element of c contains all elements of y at the positions where x=1 and so on:

x=   [ 1  1  1  2  2  3  3  3  3];
y=   [10 52 12 58 21 43 89 27 98];
c{1}=[10 52 12];
c{2}=[         58 21];
c{3}=[               43 89 27 98];

Solution Stats

67.78% Correct | 32.22% Incorrect
Last Solution submitted on Jun 01, 2025

Problem Comments

Solution Comments

Show comments
MATLAB EXPO 2025 Registration is Now Open! November 12 – 13, 2025
Registration is now open for MathWorks annual virtual event MATLAB EXPO 2025...
0

Problem Recent Solvers57

Suggested Problems

Problem Tags

Community Treasure Hunt

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

Start Hunting!