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

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

  •  19-07-2023
  •  | 
  •  

문제

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.

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top