Doing calculation across columns

조회 수: 6 (최근 30일)
Nick DeMarchis
Nick DeMarchis 2019년 4월 22일
댓글: Jenny Hall 2020년 10월 22일
Hi there. I have a 4 column by 500 row matrix. How would I add a fifth column that calculates , where x is the corresponding value in the second column across the same row.
Thanks!

채택된 답변

madhan ravi
madhan ravi 2019년 4월 22일
D=zeros(500,5);
D=matrix;
D(:,5)=exp((-(matrix(:,2)-75)/2).^2)
  댓글 수: 3
Stephen23
Stephen23 2020년 10월 22일
편집: Stephen23 2020년 10월 22일
x(:,2) = (((6.64e-34)*(9.5e+9))./((9.274e-24)*(x(:,1)/10000)))
% ^^ you might want array division here
Jenny Hall
Jenny Hall 2020년 10월 22일
Thank you! This worked a treat.

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

추가 답변 (1개)

JULIEN BARBAUD
JULIEN BARBAUD 2019년 4월 22일
편집: JULIEN BARBAUD 2019년 4월 22일
I think that if you call your input matrix A, and the final result B, then this:
f=@(x) exp( (-(x-75)/2).^2 )
B=[A f(A(:,2))];
should do the trick
EDIT: oops, madhan was quicker

카테고리

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

태그

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by