Reshape and Modify a cell array

6 visualizaciones (últimos 30 días)
Marcelo Boldt
Marcelo Boldt el 3 de Oct. de 2020
Comentada: Marcelo Boldt el 3 de Oct. de 2020
Dear Community,
I have a 294x1 cell array, where each variable is a number and from this cell I need to create 2 cell arrays each of 49x1, where each variable of this new cell arrays contains 3 variables of the first array. How would you do that?
This is what I got so far:
Last_vektor = num2cell(Ubertragungsmatrix(:,end));
Load_vector = reshape(Last_vektor,[98,1]);
Pu_tr = cell(49,1);
Pn_tr = cell(49,1);

Respuesta aceptada

madhan ravi
madhan ravi el 3 de Oct. de 2020
Editada: madhan ravi el 3 de Oct. de 2020
Vielleicht?
C = num2cell(reshape(Ubertragungsmatrix(:, end), 294/2, []), 1);
C1 = num2cell(cellfun(@(x) {reshape(x, [], 3)}, C));
[Pu_tr, Pn_tr] = deal(C1{ : })
  2 comentarios
Marcelo Boldt
Marcelo Boldt el 3 de Oct. de 2020
It is an interesting approach indeed, but now I am getting 1x1 cell (49x3 double), no Idea how to modify that
madhan ravi
madhan ravi el 3 de Oct. de 2020

Iniciar sesión para comentar.

Más respuestas (1)

madhan ravi
madhan ravi el 3 de Oct. de 2020
Bessere Version:
V = reshape(Ubertragungsmatrix(:, end), [], 3, 2);
V1 = squeeze(num2cell(V, [1, 2]));
[Pu_tr, Pn_tr] = deal(V1)
  3 comentarios
madhan ravi
madhan ravi el 3 de Oct. de 2020
Editada: madhan ravi el 3 de Oct. de 2020
It’s assumed that Ubertragungsmatrix(:, end) is a vector with 294 elements. size(Pu_tr) size(Pn_tr) % paste the output here
Marcelo Boldt
Marcelo Boldt el 3 de Oct. de 2020
yes that's right, its a 294x1 vector. that I want to convert to two 49x1 cell, each variable contianing a 3x1 vector

Iniciar sesión para comentar.

Categorías

Más información sobre Matrix Indexing 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