Error Brace indexing is not supported
이전 댓글 표시
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
"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
2023년 4월 4일
Stephen23
2023년 4월 4일
"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.
채택된 답변
추가 답변 (1개)
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
Life is Wonderful
2023년 4월 4일
Bora Eryilmaz
2023년 4월 4일
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
2023년 4월 4일
카테고리
도움말 센터 및 File Exchange에서 Exploration and Visualization에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!