Store fit output and call them later

2 visualizaciones (últimos 30 días)
Hussein Kokash
Hussein Kokash el 20 de Jun. de 2021
Comentada: Hussein Kokash el 20 de Jun. de 2021
Dears, hope all are doing great!
I have the following script I use to read files and then fit them using curve fitting, my goal is to store the output of the fit for each file so that I can plot them all using the same x-axis, so the idea is to replace y values with the new fit output for each file, how is that possible?
Thank you, appreciate it.
[file_list, path_n] = uigetfile('.txt', 'Multiselect', 'on');
filesSorted = natsortfiles(file_list);
if iscell(filesSorted) == 0;
filesSorted = (filesSorted);
end
for i = 1:length(filesSorted);
filename = filesSorted{i};
data = load([path_n filename]);
x = data (:,1);
y = data (:,2);
T = data (1,3);
Time(i) = T;
% Curve fitting
f=fit(x, y, 'fourier1')
%figure(i)
plot(f, x, y)
hold on
formula(f)
coefficients = coeffvalues(f)
end

Respuesta aceptada

Walter Roberson
Walter Roberson el 20 de Jun. de 2021
f=fit(x, y, 'fourier1')
Once you have that, you could record f in a cell array.
Or... you can invoke
saved_x{i} = x;
saved_y{i} = y;
predicted_y{i} = f(x);
Here, predicted_y{i} will become a numeric vector of what the model values predict for the given x values; you would not need the fit object after that.
  3 comentarios
Walter Roberson
Walter Roberson el 20 de Jun. de 2021
plot(saved_x{i}, predicted_y{i})
Hussein Kokash
Hussein Kokash el 20 de Jun. de 2021
Superb!
Thank you!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Get Started with Curve Fitting Toolbox en Help Center y File Exchange.

Productos


Versión

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by