# Simulink error: The data abscissae must be distinct and strictly monotonic.

조회 수: 26(최근 30일)
Kostas 17 Oct 2019
Edited: Kostas 17 Oct 2019
Hi all,
I have constructed a simulink model, where within the model I have a MATLAB function block as you can see. Within that block, a very simple code loads data from a .mat file and interpolates using interp1.
However I get the following error when I run the model which I have managed to trace to the line in the MATLAB function block where the interpolation occurs:
An error occurred while running the simulation and the simulation was terminated
Caused by:
• The data abscissae must be distinct and strictly monotonic.
This is simple enough, as one would assume that my x vector in the interp1 function includes non-monotonic data. But the problem is that it doesn't! I have tested that by running the code in the MATLAB function block by itself as a normal matlab file, and also used unique to tripple check and it works perfectly. I also checked where the current folder to ensure that the file is taken from the right place. So I really do not know why the interp1 function presents this problem when I am running it in Simulink. It must be something that I don't understand.
Any suggestions?
Kind Regards,
KMT.
P.S. Attached you can find the files that I am using. Just download and run if you need to.

로그인 to comment.

### 채택된 답변

Daniel M 17 Oct 2019
Daniel M 님이 편집함. 17 Oct 2019
None of the variables in the matfile are monotonic.
all(sign(diff(Tga))==1) % ans = 0
all(sign(diff(Tm1))==1) % ans = 0
all(sign(diff(Tm2))==1) % ans = 0
all(sign(diff(thx))==1) % ans = 0
x = -10:10;
all(sign(diff(x))==1) % ans = 1
Perhaps try unwrap, as the values of thx seem to be between -pi and pi.

#### 댓글 수: 5

표시 이전 댓글 수: 2
Kostas 17 Oct 2019
Hi Daniel,
So I did the checks that you did as well and you are right. The thx vector is a vetor that spans from -20 to -19 degrees, hence at 0 (or 180 degrees) the vector is non-monotonic. I managed to therefore make thx monotonic using sort.
However there is stil somethig weird happening, which was also happening before (hence why I assumed the vector was monotonic to begin with). When I use interp1 on the un-sorted thx vector it still works! I do not understand why... Does the same thing happen to you when you try to run interp1 with the un-sorted vector outside simulink?
e.g. if you try to run
interp1(thx, Tga, 1.2)
Edit: it worked in Simulink when I did the following:
[~,i] = sort(thx) ;
thxS = thx(i) ;
TgaS = Tga(i) ;
T_G = interp1(thxS, TgaS, input_variable) ;
Daniel M 17 Oct 2019
I have solved it. If you unwrap thx such that it become monotonic, now there is a duplicate! It occurs because thx has entries for 3.1416 and -3.1416 (and unwrapped they become the same). So I removed the second entry.
thx(201) = [];
Tga(201) = [];
thx = unwrap(thx);
And this function shouldn't have any more problems. And the simulink program generates an error further along the simulation (hey... it's still progress!).
Kostas 17 Oct 2019
Ok, I understand. Thanks very much for your help!

로그인 to comment.