Splitting a column (and a numerical value in that column) into multiple columns

1 visualización (últimos 30 días)
Hello, I have a following problem: I have multiple columns in a matrix. In all of the columns I have a numerical value, let's say 20. I need to (under some conditions) split a single column into 5 separate ones, and I need these 5 columns to carry a number which is the original 20 divided by the new number of columns - 5 (so at the end I will have, out of one column with a number 20 in it - five columns with a number 4 in them). Does anyone have an idea how could I do that? Thanks!

Respuesta aceptada

Stephen23
Stephen23 el 28 de Sept. de 2018
Editada: Stephen23 el 28 de Sept. de 2018
Divide, then use mat2cell
  6 comentarios
Stephen23
Stephen23 el 28 de Sept. de 2018
Editada: Stephen23 el 28 de Sept. de 2018
>> M = rand(2094,5); % fake data matrix
>> N = 5; % number of groups
>> S = size(M);
>> R = diff(round(0:S(1)/N:S(1))) % rows per group
R =
419 419 418 419 419
>> C = mat2cell(M,R,S(2));

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Characters and Strings en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by