필터 지우기
필터 지우기

How can I calculate the grouped data?

조회 수: 2 (최근 30일)
wd w
wd w 2024년 2월 16일
댓글: Dyuman Joshi 2024년 2월 16일
I have some grouped data, and intend to perform an element-wise squaring one by one and find out the minimum of calculated results of each grouped data. The following is an example, but unfortunately it doesn't work.
x11 = [1 2 3 6 5 4];
x22 = [11 12 13 16 15 14];
y(ii) = x(ii).^2;
m(ii) = min(y(ii))

채택된 답변

Dyuman Joshi
Dyuman Joshi 2024년 2월 16일
Dynamically naming variables is not a good programming practice - TUTORIAL: Why Variables Should Not Be Named Dynamically (eval)
An efficient method is to store the data in an array -
x= [1 2 3 6 5 4; 11 12 13 16 15 14];
%Element-wise power
y = x.^2
y = 2×6
1 4 9 36 25 16 121 144 169 256 225 196
%Find the minimum of each row
m = min(y, [], 2)
m = 2×1
1 121
If the data does not have compatible dimensions for concatenating into a numeric array, consider storing the data in a cell array, and perform operations on the data accordingly.
  댓글 수: 2
wd w
wd w 2024년 2월 16일
이동: Dyuman Joshi 2024년 2월 16일
Dyuman Joshi, thank you very much!
Dyuman Joshi
Dyuman Joshi 2024년 2월 16일
You're welcome!

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Data Types에 대해 자세히 알아보기

태그

제품


릴리스

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by