how can I find the maximum value in each row of a matrix and sum along the column then assign the values to another matrix

조회 수: 1 (최근 30일)
example
2 3
3 4
5 3
1 2
3 2.5
the answer will be a vector (5+3, 3+4+2) the code may be incorrect but, I only try my assumptions.
v=[1400 1600 1200 800 1000];
r=[500 400];
for i=1:numel(v)
t=0;
for j=1:numel(r)
eet(i,j)=v(i)./r(j);
et(i,j)=v(i)./r(j);
c(i,j)=eet(i,j)+t;
ctc(i,j)=eet(i,j)+t;
t=t+eet(i,j);
end
end;
M=max(eet,[],2); % this gives me all the maximum value along a colunm vector
  댓글 수: 2
Stephen23
Stephen23 2017년 10월 24일
@Bashir Yusuf Bichi: today I formatted your code correctly for you. Please do not keep reverting it. In future you can format it correctly yourself: simply select the code text, then click the {} Code button.

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

채택된 답변

Stephen23
Stephen23 2017년 10월 24일
편집: Stephen23 2017년 10월 24일
All you need is max and accumarray:
>> M = [2,3;3,4;5,3;1,2;3,2.5];
>> [V,I] = max(M,[],2);
>> B = accumarray(I,V)
B =
8
9
  댓글 수: 5

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by