How to efficiently convert from uniquely ordered cell array back to 1-D vector?

I am initially given a very large complex-valued vector cV of a size mx1. Then, I convert this vector into a cell array I call rings. Each row in the cell array represents a unique particular magnitude value (corresponds to complex-valued column entries) sorted in an ascending order. Both the rows of the cell array and the entries in each row (i.e., columns) are sorted in an ascending order. The following code just do this (Thanks to Walter Roberson for his help on accumarray).
[sorted_Vc, ind_sorted_Vc]=sort(cV);
% Magnitude of sorted vector
abs_sorted_Vc = abs(sorted_Vc);
[tt, tt_a, tt_b] = unique(abs_sorted_Vc);
% rings is a cell array where elements (columns) represent magnitudes in a ascending order
rings = accumarray(tt_b(:), sorted_Vc(:), [], @(x) {x(:)});
% Do the same for the vector indices
ind=accumarray(tt_b(:), ind_sorted_Vc(:), [], @(x) {x(:)});
Besides the sorted rings, this code keeps track of the indices in each element in the cell array and stores them in ind.
My question is, using only rings, and ind, I would like to convert the data back to its original 1-D format and order as given in cV above. What is the most efficient way to do this in Matlab given that I am dealing with very large vector length cV on the order of millions.
Thanks in advance.

 Risposta accettata

why? What is to gain from this?
To extract from a cell:
vertcat(C{:})
or
cell2mat(C)

1 Commento

Thanks very much Sean for the answer. The reason I am doing forward-reverse conversion is that in-between the two I am applying some mathematical operations on the sorted cell array. I was doing it using a for loop which extensively slowed down my program when dealing with a very large vector. Really, Matlab rocks!

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Operators and Elementary Operations in Centro assistenza e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by