MATLAB: Detrend specified inputs/outputs

detrend iddata system identifcationMATLABSystem Identification Toolbox

Hi,
I have a data set composed of several inputs and outputs in the form.
data = idata(Y,U,Ts)
Where Y is my outputs and U are my inputs.
I would like to use the detrend function to deterrent only some of my inputs and outputs. Others I want to leave as they are. However,
data_d = detrend(data)
detrends all my data.
Thank you for any help you can offer.

Best Answer

I worked out a way to do this. I'll post it case anyone has similar issues in the future.
For a time-domain data that is defined as:
data = iddata(Y,U,Ts);
Where Y and U are multiple inputs and outputs respectively. Specific inputs and outputs can be called using:
data_c(:,{'y1','y2','y4','y5','y6'},{'u1','u2','u3'})
We can then detrend the stated outputs only.
data_r = detrend(data_c(:,{'y1','y2','y4','y5','y6'},{'u1','u2','u3'}));
However, we must re-build the iddata.
Yf = [data_r.y(:,1) data_r.y(:,2) data.y(:,3) data_r.y(:,3) data_r.y(:,4) data_r.y(:,5)];
Uf = [data_r.u(:,1) data_r.u(:,2) data_r.u(:,3) data.u(:,4)];
data_f = iddata(Yf,Uf,Ts);
Note that the detrend data has changed the order of the inputs and outputs, with the numerical values following the order they were entered. You must adjust accordingly.