Restructure column vectors into matixes

2 views (last 30 days)
I have a .mat file with several variables, one of them date. The data in all variables are in a one column vector and correspond to each other.
I would like to restructure each vector into a matrix based on the date vectror, i.e. the unique values in the date vector will become one column each, and the same for all other variables.
There must be a easy solution to this using the unique function, but I cannot figure it out.....

Accepted Answer

KSSV
KSSV on 4 May 2020
Let dates be your date and A be your column vector whcih you want to reconstruct.
[C,ia,ib] = uniqur(dates) ; % if this dont work convert dates to datenum
N = length(C) ;
iwant = cell(N,1) ; % cell becuase there is no rule that there will same number of elements to frame matrix
for i = 1:N
iwant{i} = A(ib==i) ;
end

More Answers (0)

Community Treasure Hunt

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

Start Hunting!