필터 지우기
필터 지우기

How to extract array from the mean directly using indexing?

조회 수: 2 (최근 30일)
William
William 2023년 7월 6일
편집: Nikhil Baishkiyar 2023년 7월 6일
A = [2.29441228002842 17.3351873969651 2.79928860040389 7.17554281085515;
3.16200415659481 16.9975006219209 3.18395042061777 7.45747601536461;
4.55387378846938 13.4948344868957 3.22594708715312 7.49001605579868]
meanA = mean(A,1)
output: [3.3368 15.9425 3.0697 7.3743]
how can i get second element of mean in one line?
ex:
mean(A,1)(2)
  • (2) is index
But, it is not working. Thanks.

채택된 답변

Nikhil Baishkiyar
Nikhil Baishkiyar 2023년 7월 6일
편집: Nikhil Baishkiyar 2023년 7월 6일
A = [2.29441228002842 17.3351873969651 2.79928860040389 7.17554281085515;
3.16200415659481 16.9975006219209 3.18395042061777 7.45747601536461;
4.55387378846938 13.4948344868957 3.22594708715312 7.49001605579868]
A = 3×4
2.2944 17.3352 2.7993 7.1755 3.1620 16.9975 3.1840 7.4575 4.5539 13.4948 3.2259 7.4900
mean(A(:,2))
ans = 15.9425
You mean something like this?
subindex = @(matrix, r) matrix(r); % An anonymous function for indexing
value = subindex(mean(A,1), 2) % Use the function to index the vector
value = 15.9425
  댓글 수: 3
William
William 2023년 7월 6일
편집: William 2023년 7월 6일
Yeah.. But we only got second column. It seems we will use mean four times. if there is thousands?
Actually, all of data is needed. and indexing is what can solve the problem and can ellimitate the time complexity. or we can use two lines to make the mean variable.
Nikhil Baishkiyar
Nikhil Baishkiyar 2023년 7월 6일
편집: Nikhil Baishkiyar 2023년 7월 6일
I read the post and updated my answer based on that. If you want every mean value you will have to store it in a temporary variable I am afraid

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by