How to make the sizes of all variable same in the loop.
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
KSSV
2022-1-4
% 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.
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!