# How can I create matrix with parameter?

7 visualizaciones (últimos 30 días)
Hokkien el 13 de Sept. de 2020
Comentada: Hokkien el 18 de Sept. de 2020
I wish to create a matrix based on different energy and its maximum recoil energy.
The maximum recoil energy formula is T_max = E/[1+M/(2*E)]
The example as below:
Energy, E (MeV) Recoil Energy, T
1 0 0.01 0.02 0.03 T_max_1 0 0 0
2 0 0.01 0.02 0.03 0.04 ... T_max_2 0 0
3 0 0.01 0.02 0.03 0.04 0.05 ... T_max_3 0
4 0 0.01 0.02 0.03 0.04 0.05 0.06 ... T_max_4
So for each energy, I know the maximum recoil energy for each E.
For each row of E, I want to start with 0 with energy bin width 0.01 and end with their own maximum recoil energy. Anything more than their own maximum recoil energy should be zero.
I can caculate the T_max and then write it as [0:0.01:T_max] for each energy. However, I don't know how to put all of the recoil energy into a single matrix and made anything more than their T_max is equal to zero. It can be very tedious if I have a lot of energy group and very small energy bin width.
Hope if anyone can suggest a better way to solve this problem. Thank you!
##### 0 comentariosMostrar -2 comentarios más antiguosOcultar -2 comentarios más antiguos

Iniciar sesión para comentar.

Matt J el 13 de Sept. de 2020
Editada: Matt J el 13 de Sept. de 2020
It seems like the kind of thing you would want a function for, rather than a matrix.
RecoilEnergy=@(E,r) r.*(r<=E./(1+M./(2*E)))
##### 1 comentarioMostrar -1 comentarios más antiguosOcultar -1 comentarios más antiguos
Hokkien el 18 de Sept. de 2020
I see. Thank you so much for the solution!

Iniciar sesión para comentar.

### Categorías

Más información sobre Waveform Generation en Help Center y File Exchange.

### Community Treasure Hunt

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

Start Hunting!

Translated by