Info

この質問は閉じられています。 編集または回答するには再度開いてください。

How to detect a column which gives me maximum value of the result.

1 回表示 (過去 30 日間)
Prakhar Modi
Prakhar Modi 2019 年 8 月 15 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
Hello everyone,
for example I have to calculate z using the equation
z=y-x
here y is 15x1 matrix and x is also 15x1 matrix. I have 15 set of x which is 15x1 matrix and we can assume it as x=15x15 matrix. Now take a look at the code
for j=1:15
for i=1:15
z(i,j)=y(i)-x(i,j);
end
end
here I am getting the z as 15x15 matrix. Then I am calculating the sum of z. So for the maximum sum of z i want to know which 15x1 matrix of x have provided the max z. And assign it as x1 for further calcultation.
Thanks in advance.

回答 (1 件)

Star Strider
Star Strider 2019 年 8 月 15 日
Try this:
x = rand(15); % Create Matrix
y = rand(15,1); % Create Vector
[~,maxCol] = max(sum(y - x)) % Result

製品


リリース

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by