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!

 Akzeptierte Antwort

madhan ravi
madhan ravi am 22 Apr. 2019

0 Stimmen

D=zeros(500,5);
D=matrix;
D(:,5)=exp((-(matrix(:,2)-75)/2).^2)

3 Kommentare

Jenny Hall
Jenny Hall am 22 Okt. 2020
I am currently trying to do something similar, in order to carry out a calculation of every value in one column. This code I have written is as follows:
x(:,2) = (((6.64e-34)*(9.5e+9))/((9.274e-24)*(x(:,1)/10000)))
However this only seems to calculate a value for the final row in the column, whilst all of the values come out as 0. The column contains 1024 rows.
Any help would be much appreciated!
Stephen23
Stephen23 am 22 Okt. 2020
Bearbeitet: Stephen23 am 22 Okt. 2020
x(:,2) = (((6.64e-34)*(9.5e+9))./((9.274e-24)*(x(:,1)/10000)))
% ^^ you might want array division here
Jenny Hall
Jenny Hall am 22 Okt. 2020
Thank you! This worked a treat.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

JULIEN BARBAUD
JULIEN BARBAUD am 22 Apr. 2019
Bearbeitet: JULIEN BARBAUD am 22 Apr. 2019

0 Stimmen

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

Kategorien

Produkte

Version

R2019a

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by