Error Brace indexing is not supported
Show older comments
Hi there,
I am having an odd problem, and I'm not sure how to fix the error below. Any assistance would be greatly appreciated.
Brace indexing is not supported for variables of this type.
Many thanks
Following is the code i am using
imageFileNames = imageFileNames(imagesUsed);
originalImage = imread(imageFileNames{1});
Brace indexing is not supported for variables of this type.
class(imageFileNames)
ans =
'char'
imageFileNames
imageFileNames =
'rcngvieo ram'
where imagesUsed =
25×1 logical array
0
0
1
0
0
0
0
1
0
1
1
0
1
1
0
1
1
1
0
1
1
1
0
0
0
3 Comments
"I am having an odd problem"
It is not odd at all: the variable imageFileNames is a character array, for which curly brace indexing is not defined.
Thus the error.
"I'm not sure how to fix the error below. Any assistance would be greatly appreciated."
Do you expect imageFileNames to be a cell array? If so, then you will need to check your code for the place where you replaced the expected cell array with a char array of the exactly same name (because it isn't in the code that you showed us). That will fix the error.
Life is Wonderful
on 4 Apr 2023
Stephen23
on 4 Apr 2023
"This is not a cell array, it's a char "
Sure, which is exactly why you cannot use curly brace indexing with it.
However I did not ask you what it is, I asked you what you expect it to be. A totally different question.
Accepted Answer
More Answers (1)
Bora Eryilmaz
on 4 Apr 2023
Edited: Bora Eryilmaz
on 4 Apr 2023
Your imageFileNames variable is not a cell array, so you cannot use brace indexing with it. It is a long char array with words separated by spaces. You can use the split command to generate a cell array of char variables from it:
imageFileNames = 'rcngvieo ram'
names = split(imageFileNames, ' ')
names{1}
names{2}
3 Comments
Life is Wonderful
on 4 Apr 2023
Bora Eryilmaz
on 4 Apr 2023
I am assuming 'ram' is the file extension for your image file. If that is the case, the way you construct the imageFileNames variable is problematic. The imread command needs the full name of the file, including the file extension.
Life is Wonderful
on 4 Apr 2023
Categories
Find more on Entering Commands 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!