Cell array multiplication error

1 view (last 30 days)
Nevzat Can Yerlikaya
Nevzat Can Yerlikaya on 8 Jun 2022
Commented: Jan on 9 Jun 2022
Hi everyone, I have a code like this:
for i=1:18
for j=1:5
in each r_prob cell, there is a 1000 randomly generated numbers. I run this code and it was successful and I close it down. However, when I try to run it again, it gaves me an error "Unable to perform assignment because brace indexing is not supported for variables of this type." for B{i,j}=AvgMatrix(i,j)*r_prob{i,j}. Does anyone know what is the problem? Any help would be appreciated. Thank you a lot.

Accepted Answer

Jan on 8 Jun 2022
Edited: Jan on 8 Jun 2022
The error message means, that either B or r_prob is not a cell array. Use the debugger to find out, what type it is instead. Type this in the command window:
dbstop if error
Run your code again, when it stops, check the variables:
Is B pre-allocate as cell before?
Is this a script or a function? In a script you are using the workspace of the caller. So if B was created as a cell array before in the command window by accident, the code ran. But now with a clean workspace the code fails. This is the reason why scripts should be avoided in productive projects, because they cannot be debugged and tested exhaustively and have severe long range side effects.
Jan on 9 Jun 2022
Because this is the typical problem of working with scripts, decide for using functions for all of your projects.

Sign in to comment.

More Answers (0)


Find more on Multidimensional Arrays in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!