How to properly access values in an array, within a cell array, within a struct?
2 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Walter Roberson
2021-2-9
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.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Structures 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!