How can I calculate the grouped data?
1 回表示 (過去 30 日間)
古いコメントを表示
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))
0 件のコメント
採用された回答
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
%Find the minimum of each row
m = min(y, [], 2)
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 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Logical についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!