MATLAB: How to unscale rescaled data

rescale-unscale

I have time series data that i rescaled to values between -1,1 using the rescale function i.e.
scaled_data = rescale(data,-1,1);
I have use this data do a prediction and would now like to plot he prediction and confidence intervals in the orginal scale. Is there a way to do this? I tried
prediction_org_scale = rescale(prediction,min(data),max(data));
but realised that this is incorrect and am stuck with how to proceed.
Thanks for any help!

Best Answer

You simply need to reverse the formula (which is given in the documentation of rescale. In your particular case:
prediction_org_scale = (prediction + 1) * (max(data) - min(data)) / 2 + min(data);
The generic formula:
unscale = @(data, l, u, inmin, inmax) (data - l) * (inmax - inmin) / (u - l) + inmin;