1

I have a large array of dimension 64x4x45x14.

I initialize it to all zeros as:

Main = zeros(64,4,45,14);

I have another array S_avg of dimension 45x14 ;

If I do something like this, why does Matlab give an error?

Main(chan_no,level,:,:) = Main(chan_no,level,:,:) + S_avg ;

2 Answers 2

1

You can remove the singleton dimensions with squeeze.

Use this code instead,

Main(chan_no,level,:,:) = squeeze(Main(chan_no,level,:,:)) + S_avg ;

The reason is that,

size(Main(chan_no,level,:,:)) = 1   1   45   14

While,

size(S_avg) = 45   14

so you get a dimension mismatch error.

Sign up to request clarification or add additional context in comments.

Comments

0

You have to reshape the matrix S_avg first, try this here

Main(chan_no,level,:,:) = Main(chan_no,level,:,:) + reshape(S_avg, 1, 1, size(S_avg, 1), size(S_avg, 2)) ;

or if you know the size of S_avg for sure

Main(chan_no,level,:,:) = Main(chan_no,level,:,:) + reshape(S_avg, 1, 1, 45, 14) ;

Comments

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.