0

I have 3x2 cell array called signals. All cells contain a 8x6xN array full of integers. I am trying to move down every row by one row and overwrite the first row with NaNs. Howevery, I am struggling with the correct syntax regarding indexing. I am able to manipulate one particular cell like this:

signals{1,1}(2:end, :) = signals{1,1}(1:end-1, :);
signals{1,1}(1,:) = NaN;

How can I apply this manipulation to the whole cell array? I am basically looking for something like this:

signals{:}(2:end, :) = signals{:}(1:end-1, :);

1 Answer 1

1

You need to loop through each element in the cell array and perform the operation on each of these elements.

for k = 1:numel(signals)
    signals{k}(2:end, :) = signals{k}(1:end-1, :);
    signals{k}(1,:) = NaN;
end
Sign up to request clarification or add additional context in comments.

2 Comments

Is there a way to solve that problem without using a loop. I am looking for the most efficient way in terms of speed as the signals matrix may become quite large.
@Andi No. Thanks to JIT acceleration, the performance penalty for using a loop such as this is minimal. Also, if you really want performance, then I would use a multi-dimensional array rather than a cell array if possible.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.