Reshape list into columns
2 views (last 30 days)
Im working with driving data for vehicles. There is 429 vehicles (DeviceStats). For the trips, there is a list of 107910 rows with one value per row (Car). The value is the id number of the vehicles. The format of the list looks like this
and so on. Every vehicle has a different number of vehicles in the Car vector. I want to reshape the list to 429 columns, where each column has the length the same length as the vehicle has in the Car-list. Like this
173 178 184
My approach so far has not worked:
Gargi Patil on 15 Apr 2021
I understand that you would like to create a matrix with each column containing same elements and each row having unique elements.
You have asked a similar question here which has been answered:
To extend the above solution further:
list = [173 173 173 178 178 184];
%Get unique elements in list
num = numel(uniqueEle);
res = zeros(num,num);
ii = 1;
for i = 1:numel(uniqueEle)
output = list(list(:,1)==uniqueEle(i),:);
%Append zeros to make output of length num
res(:, ii) = output;
ii = ii + 1;
res will return the desired output matrix.
The rows can be converted to cell arrays using num2cell().