How to get predicted values (independent variable) for each observation in Matlab?

StackOverflow https://stackoverflow.com/questions/23582660

  •  19-07-2023
  •  | 
  •  

Frage

I ran a regression in Matlab and got the normal results (coefficients etc.). I would like to ask, how can I now calculate the predicted values (independent variable) of this model for each observation in my dataset and then save the values directly to a file?

Thanks for your help.

War es hilfreich?

Lösung

If you have some arbitrary function that you've fitted your data to, then you can write a separate function like so:

function y_pred = calcy(coeffs,xvals)
%%//coeffs is a vector of the fitted coefficients, x is a vector
%%//Calculate the predicted values here using whatever model you're using and the fitted
%%//coefficients and x-values

end

In your main function you'll call:

y_pred = calcy(coeffs,xvals);
dlmwrite('file.txt',y_pred);

This will write the vector in comma-delimited format to your directory. You can look at documentation of dlmwrite for how to change the format to suit your needs.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top