Question

y is 40x4x10, y(i,:,:) is 1x4x10, and K is 4x10.

I would like to: y(i,:,:) = y(i,:,:) + K but I get a dimension error. I cannot use squeeze because I need the rest of y.

How do I perform this addition?

Was it helpful?

Solution

You have to permute the dimensions, to make K 1x4x10, like this:

y(i,:,:) = y(i,:,:) + permute(K, [3 1 2])

Note K is "kind of" 4x10x1. We are asking to consider first the 3rd dimension, then the 1st, and the 2nd.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top