why do I get this error in the simulation

I'm doing a reactor simulation and it's a long one and it works but now when I add some changes I got this error
Error using griddedInterpolant
The grid vectors must contain unique points.
Error in interp1 (line 161)
F = griddedInterpolant(X,V,method);
Error in reactor_simulation>cross (line 431)
Sig_s_tot_O16_interp = interp1(oxygen_energy_tot, oxygen_cross_tot, e, 'linear');
Error in reactor_simulation>dist2c (line 505)
value = - log ( u ) / cross ( e );
Error in reactor_simulation (line 215)
[ d, seed ] = dist2c ( e, seed );
as I understand that the error because the data file I use does not has a unique points (the energy) so I used this code to found the simller points and I change them to became unique
for i=1:max(size(oxygen_data_tot))-1
if(oxygen_data_tot(i,1)==oxygen_data_tot(i+1))
i=i
end
end
but the problem is that I got the same error again after changing all the poin, so can you help me to know whats the problem to solve it?

 Respuesta aceptada

Torsten
Torsten el 23 de Mzo. de 2023
Editada: Torsten el 23 de Mzo. de 2023
Before calling "interp1", use
% Sort array oxygen_energy_tot in ascending order
[oxygen_energy_tot_sorted,idx_sort] = sort(oxygen_energy_tot);
oxygen_cross_tot_sorted = oxygen_cross_tot(idx_sorted);
% Delete duplicate values of oxygen_energy_tot
[oxygen_energy_tot,idx_unique] = unique(oxygen_energy_tot_sorted);
oxygen_cross_tot = oxygen_cross_tot_sorted(idx_unique);

3 comentarios

Moza
Moza el 24 de Mzo. de 2023
I got this error:
Undefined function or variable 'idx_sorted'.
Error in reactor_simulation>cross (line 426)
oxygen_cross_tot_sorted = oxygen_cross_tot(idx_sorted);
Error in reactor_simulation>dist2c (line 508)
value = - log ( u ) / cross ( e );
Error in reactor_simulation (line 211)
[ d, seed ] = dist2c ( e, seed );
Use
[oxygen_energy_tot_sorted,idx_sorted] = sort(oxygen_energy_tot);
instead of
[oxygen_energy_tot_sorted,idx_sort] = sort(oxygen_energy_tot);
Moza
Moza el 24 de Mzo. de 2023
thank you it workes

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Interpolation en Centro de ayuda y File Exchange.

Productos

Versión

R2016b

Preguntada:

el 23 de Mzo. de 2023

Comentada:

el 24 de Mzo. de 2023

Community Treasure Hunt

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

Start Hunting!

Translated by