# How do I solve the error "Brace indexing is not supported for variables of this type"

**URL:** <https://psychtoolbox.discourse.group/t/how-do-i-solve-the-error-brace-indexing-is-not-supported-for-variables-of-this-type/4116>\
**Category:** Programming Help\
**Tags:** experiment-design\
**Created:** [November 15, 2021, 5:57pm UTC](https://psychtoolbox.discourse.group/t/how-do-i-solve-the-error-brace-indexing-is-not-supported-for-variables-of-this-type/4116 "2021-11-15T17:57:58Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Cai](https://avatars.discourse-cdn.com/v4/letter/c/6f9a4e/32.png) [@Cai](https://psychtoolbox.discourse.group/u/Cai)\
**Post date:** [November 15, 2021, 5:57pm UTC](https://psychtoolbox.discourse.group/t/how-do-i-solve-the-error-brace-indexing-is-not-supported-for-variables-of-this-type/4116/1 "2021-11-15T17:57:58Z")

</div>

Hi,

I am attempting to index the variable ‘seq1’ which is a double composed of 12 random numbers between 1 and 9, and then use the output of this indexing to index another variable called ‘rectColor’, which is a cell comprised of 3 numbers defining a grayscale colour, as shown. However, when I run the following code, I get this error:

% Define grayscales  
rectColor{1} = [0.1 0.1 0.1];  
rectColor{2} = [0.15 0.15 0.15];  
rectColor{3} = [0.22 0.22 0.22];  
rectColor{4} = [0.30 0.30 0.30];  
rectColor{5} = [0.40 0.40 0.40];  
rectColor{6} = [0.55 0.55 0.55];  
rectColor{7} = [0.7 0.7 0.7];  
rectColor{8} = [0.85 0.85 0.85];  
rectColor{9} = [1 1 1];

% Substitute numbers for grayscale images  
for i = 1:12  
seq1(i) = cell2mat(rectColor{seq1(i)});  
end

Brace indexing is not supported for variables of this type.

Error in cell2mat (line 42)  
cellclass = class(c{1});

Error in perceptual\_trial\_grayscale (line 223)  
seq1(i) = cell2mat(rectColor{seq1(i)});

I would very much appreciate any advice regarding how to solve this issue. Thanks in advance.

---

<div class="post-metadata">

**Author:** ![dcnieho](https://avatars.discourse-cdn.com/v4/letter/d/779978/32.png) [@dcnieho](https://psychtoolbox.discourse.group/u/dcnieho)\
**Post date:** [November 15, 2021, 11:02pm UTC](https://psychtoolbox.discourse.group/t/how-do-i-solve-the-error-brace-indexing-is-not-supported-for-variables-of-this-type/4116/2 "2021-11-15T23:02:44Z")

</div>

rectColor{1} or whatever index is already not a cell, so remove the cell2mat call
