How to properly access values in an array, within a cell array, within a struct?
2 views (last 30 days)
Show older comments
Steve Francis
on 9 Feb 2021
Commented: Steve Francis
on 9 Feb 2021
I have a struct called myStruct with 2 fields:
Field Value
light 4x2 cell
dark 4x2 cell
If I click on myStruct.light, I see the following arrays listed
2178x3860 double 2178x3860 double
2178x3860 double 2178x3860 double
2178x3860 double 2178x3860 double
2178x3860 double 2178x3860 double
and if I click on one of these cells, say myStruct.light{3,2}, I can then see the data in that cell's 2178x3860 array.
I would like to write a line in the Command Window that enables me to extract a range of values in myStruct.light{3,2}. Let's suppose that I want to calculate the mean of all values in a 2x4 array from the top left corner of myStruct.light{3,2}
If I enter
topleft=amberLED.light{3,2}(1:2,1:4)
in the command window, it seems to work ok. A 2x4 matrix called topleft is output:
topleft =
2356 2284 2347 2350
2273 2403 2288 2342
But when I then type:
mean = mean(topleft, 'all')
I get the following error message returned:
Index in position 1 exceeds array bounds (must not exceed 1).
Please can you advise me where I'm going wrong?
0 Comments
Accepted Answer
Walter Roberson
on 9 Feb 2021
mean = mean(topleft, 'all')
You got the error the second time you tried to use the function mean(). After the first time you called mean(), you have replaced the function mean() with the array mean .
Avoid using variable names that are the same as the names of important functions.
More Answers (0)
See Also
Categories
Find more on Structures 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!