In Matlab I have an array "latencies"
(size 1x11) and a cell array "Latencies_ms"
(size 1x298). latencies
is a smaller part of Latencies_ms
, i.e. the values in latencies
exist within Latencies_ms
. I want to be able to find each value in latencies
inside Latencies_ms
and then add 1000
to that value and repeat this 8 times inside Latencies_ms
.
So for example,
latencies = [62626 176578 284690 397708 503278 614724 722466]
and (a small sample of Latencies_ms)
Latencies_ms = {3458, 62626, 123456, 7891011, 121341, 222112, 176578}
I want the output to be
out = {3458, 62626, 63626, 64626, 65626, 66626, 67626, 68626, 69626, 70626, 123456, 7891011, 121341, 222112, 176578, 177578, 178578, 179578, 180578, 181578, 182578, 183578, 184578,}
As a starting point I decided to see if I could just replicate each element without adding 1000 and I have used the following code with repmat
:
out = arrayfun( @(x,b)[x; repmat({latencies},8,1)],...
Latencies_ms, ismember(cell2mat(Latencies_ms),latencies), 'uni', 0 );
out = vertcat(out4{:});
where I match the elements of latencies with Latencies_ms and then use repmat
however using it like this inserts the entire latencies
array at the correct locations rather than repeating the elements.
Then if I try using a for-loop like this:
for i=1:length(latencies)
out = arrayfun( @(x,b)[x; repmat({latencies(i)},8,1)],...
Latencies_ms, ismember(cell2mat(Latencies_ms),latencies), 'uni', 0 );
out = vertcat(out4{:});
end
it repeats just the last element of latencies so its correctly doing the replication but not of the correct elements.
I'm not too proficient with arrayfun
and I think its whole point is to avoid using for-loops so I'm sure this isn't the correct way anyway but I feel like I'm almost there... Does anyone know what I am missing???
I don't have to use arrayfun, I tried to do this using for-loops but it got a bit messy but there isn't a restriction on using just arrayfun I just want to get to the correct output!