Check for missing argument or incorrect argument data type in call to function 'abs'.

I'm building code for getting IAE and ITAE values from a controller project.
Using a function already tested by me in other programs it returns this error message:
Check for missing argument or incorrect argument data type in call to function 'abs'.
The part of the code that is giving a problem is below:
res = sim('RTS.slx');
erroa= abs(1-res.control);
erroat = abs(dt *(1-res.control));
IAE= trapz(res.tempo, erroa);
ITAE= trapz(res.tempo, erroat);

Réponses (2)

I doubt that res.control is a numeric array. Depending what how the signal "control" is formed in the simulation RTS, you'll probably need to use addittional qualfiers to get to the actual data in res.control. For example, if control is a timeseries output from a To Workspace block, you'd need
erroa = abs(1 - res.control.Data)

11 commentaires

Well, the database refers to the output of an RST controller, making the change you suggested, it returned the following message:
Error using trapz (line 66)
Point spacing must be a scalar specifying uniform spacing or a vector of x-coordinates for each data point.
Error in Trecho2 (line 56)
IAE= trapz(res.tempo, erroa);
Now there is the same issue with res.tempo. You need additional qualification to get to the data in res.tempo that you are trying to access.
But do I use .data? When I run the code it returns:
Error using Trecho2 (line 56)
Dot indexing is not supported for variables of this type..
More information needed. Type these two lines in the command window and copy the results here
res.control
res.tempo
res.tempo
timeseries
Common Properties:
Name: ''
Time: [84x1 double]
TimeInfo: [1x1 tsdata.timemetadata]
Data: [84x3000 double]
DataInfo: [1x1 tsdata.datametadata]
More properties, Methods
ans =
0
0.2500
0.5000
0.7500
1.0000
1.2500
1.5000
1.7500
2.0000
2.2500
2.5000
2.7500
3.0000
3.2500
3.5000
3.7500
4.0000
4.2500
4.5000
4.7500
5.0000
5.2500
5.5000
5.7500
6.0000
6.2500
6.5000
6.7500
7.0000
7.2500
7.5000
7.7500
8.0000
8.2500
8.5000
8.7500
9.0000
9.2500
9.5000
9.7500
10.0000
>> res.control
timeseries
Common Properties:
Name: ''
Time: [84x1 double]
TimeInfo: [1x1 tsdata.timemetadata]
Data: [84x3000 double]
DataInfo: [1x1 tsdata.datametadata]
More properties, Methods
>>
It seem you can't subtract a time series from 1. Try to convert it to a double somehow. Maybe you meant (1-res.control.Time) or something?
@Image Analyst , the result:
Error using Trecho2 (line 55)
Dot indexing is not supported for variables of this type.
res.tempo is a timeseries as is res.control.
res.tempo.Time; % acceses the time vector
res.tempo.Data; % accesses the data values
In both cases, the Data is an 84 x 3000 array, one row per time point. It's likely, but not guaranteed, that res.tempo.Time and res.control.Time are equal to each other. I think you could do
erroa = 1 - res.control.Data;
but then erroa will be a timeseries that you can't input directly to trapz.
Maybe you you want to do something like this?
erroa = abs(1 - res.control.Data); % 84 x 3000 array
ITAE = trapz(res.control.Time,erroa) ; % should be a 1 x 3000 array, integrating each colum wrt time
The same error mensage returns
Hmm. Should work just fine:
res.control = timeseries(rand(84,3000),0:83);
res.control
timeseries Common Properties: Name: 'unnamed' Time: [84x1 double] TimeInfo: tsdata.timemetadata Data: [84x3000 double] DataInfo: tsdata.datametadata
erroa = abs(1 - res.control.Data);
iae = trapz(res.control.Time,erroa);
size(iae)
ans = 1×2
1 3000
Of course, res is just a regular structure here, not a Simulink.SimulationOutput object, but that shouldn't matter.
Do you see this after the which() command?
which trapz -all
/MATLAB/toolbox/matlab/datafun/trapz.m /MATLAB/toolbox/parallel/gpu/@gpuArray/trapz.m % Shadowed gpuArray method /MATLAB/toolbox/parallel/parallel/@codistributed/trapz.m % Shadowed codistributed method
Try operating on one column of data at a time
columnNumber = 15; % whatever...
erroa = 1 - res.control.Data(:, columnNumber);

Connectez-vous pour commenter.

res does not have a field, property, or method called control. What does this show:
res = sim('RTS.slx') % Don't use a semicolon
fieldnames(res)
properties(res)
methods(res)
v = res.control
whos v
Dont' use semicolons. If any throw errors, just comment them out and tell us what the rest display in the command window.

Catégories

Modifié(e) :

le 1 Nov 2021

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by