making rectangular matrix by non rectangular matrix by putting zeros

Hello, I have a text file data which every row has different numbers which the longest is 17 numbers. If the number of rows be n, how may I make a matrix n*17 which put zero at the end of those rows which have fewer numbers than 17? As an example this data which should be 10*17 matrix.
1 1
2
3 2 2 4 2 2 2 3 3
5
1
6
1 1
6
6 7 7 7 6 6 8 8 8 8 6 7 7 7 6 6 8
6 9 4 4 4 10 3 10 5 10 4 4 4

 采纳的回答

One approach:
c = {[1 1]; 2; [3 2 2 4 2 2 2 3 3]}; % Original Cell Array (Segment)
szc = cellfun(@size, c, 'UniformOutput',false); % Sizes Of Each Vector
M = zeros(size(szc,1), max([szc{:}])); % Preallocate
for k1 = 1:size(M,1)
M(k1, 1:szc{k1}(:,2)) = c{k1}; % Fill Each Row
end

更多回答(0 个)

类别

帮助中心File Exchange 中查找有关 Cell Arrays 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by