Undefined function 'minus' for input argum

2019-07-16 21:33发布

问题:

This is a followup to a previous issue I was having.

I want to give an offset to a signal then add some delay in it and calculate RMSE for that but when taking difference I am having the following issue:

I would like to ask the following things:

  1. How can I solve the above problem?
  2. Will anybody please explain in simple words what iddata does - because I have studied different portals including MATLAB but remained unable to get a good concept.
  3. How can I store data of type iddata in cell for subtraction in the last part of my code?

Code with Problem :

 drv(1)=load('123.mat');

 t = drv(1).x;
 ref = drv(1).y;
 angle = drv(1).z;
 Fs = 1000;              
 t1 =t';
 ref1= ref';
 d_data = iddata(ref1, t1, 1/Fs);

 %% Add offset:
 x = 1;
 afterOffset1= {};
 for i = 100:10:130 
 T = getTrend(d_data); 
 % <detrend data if needed>
 T.InputOffset = i;
 T.OutputOffset = i;
 afterOffset = retrend(d_data,T);
 afterOffset1{x,1}= afterOffset;
 x= x+1 ;
 end 

 %% Add delay:
 y=20;
 afterDelay1= {};
 for i = 1:1:4
 % delaySamples = i; % Must be a non-negative value
 % afterDelay = iddata([NaN(delaySamples,1); d_data.OutputData],...
 %                     [d_data.InputData; NaN(delaySamples,1)], 1/Fs);
 afterOffset1{i}.Tstart = y;
 afterDelay1{i,1}= afterOffset1{i};
 y= y+10;
 end 
 %% Plot:
 n = size(afterDelay1,1);
 figure();
 for i=1:1:n
 subplot(2,2,i);

 plot(d_data);
 hold all
 plot(afterDelay1{i});
 end

 sig_diff = angle(1)-afterDelay1;
 square_error(i,:) = (sig_diff(i)).^2;
 mse(i,:)=  mean(square_error(i));
 rmse(i,:) = sqrt(mse(i));


 sig_diff = d_data_1 - afterDelay; %        <<<<<<<<<<<<<<<<<<<<<< Problem is here
 %     square_error = (sig_diff).^2;
 %     mse=  mean(square_error);
 %     rmse = sqrt(mse);
 end

回答1:

You most likely want the OutputData attribute from the iddata object which is the output or y signal of your problem:

sig_diff = angle(1)-afterDelay1.OutputData;

Also note that this will give you a column vector, but your code later on assumes it's a row vector. You may want to transpose this data after you perform the above calculation before proceeding:

sig_diff = angle(1)-afterDelay1.OutputData;
sig_diff = sig_diff.';

In general, iddata is a function that creates an object that represents input and output time or frequency domain data. Take note that when you create an iddata object, the input matrix can potentially have multiple sources and so each column dictates a source. The same can be said for the output where each column dictates an output. Therefore, it is very important that you transpose your data prior to using this function to ensure that each signal is in a separate column, or just use a single column to represent one input / output.

Inside the object has a variety of attributes, including the sampling time or sampling frequency, the valid domain and range that the function takes on and finally accessing the input and output data. OutputData is one of these fields. I'd recommend looking at the documentation that talks about all of the attributes that you can access with iddata. OutputData is clearly defined here: https://www.mathworks.com/help/ident/ref/iddata.html