How to make the sizes of all variable same in the loop.
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I have 4 variables, Game0, Game1, Game2, Game3 in the for loop. I am writing these variables to excel file by using the "writetable" function. All the variables size should be same if I am writing to the excel file. How can I do that. I am using Game1(numel(Game0))=0, but this is not correct because sometimes Game0 has no value.
1 comentario
KSSV
el 4 de En. de 2022
See whose length is maximum ou t of four and append zeros to other variables.
Respuesta aceptada
KSSV
el 4 de En. de 2022
% Demo data
Game0 = rand(5,1) ;
Game1 = rand(7,1) ;
Game2 = rand(9,1) ;
Game3 = rand(3,1) ;
a = {Game0 Game1 Game2 Game3}; %test data
len = max(cellfun('length',a));
b = cellfun(@(x)[x;zeros(len-size(x,1),1)],a,'UniformOutput',false);
Game = [b{:}] ;
T = array2table(Game)
Note that there will be change in the variable name. Game1 in table is Game0.
Más respuestas (0)
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!