I've always been told that almost all for loops can be omitted in MATLAB and that they in general slow down the process. So is there a way to do so here?:
I have a cell-array (tsCell
). tsCell
stores time-arrays with varying length. I want to find an intersecting time-array for all time-arrays (InterSection
):
InterSection = tsCell{1}.time
for i = 2:length{tsCell};
InterSection = intersect(InterSection,tsCell{i}.time);
end
Here's another way. This also assumes there are no duplicates within each original vector.
Here's a vectorized approach using
unique
andaccumarray
, assuming there are no duplicates within each cell of the input cell array -Sample run -