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!