control of interpolat​ion-extrap​olation of data in the 'from file' block- matlab/simulink 2010a

5 views (last 30 days)
I am using matlab/simulink 2010a. I want to use the 'from file' block and input data into the embedded matlab function. The file is a .mat file with around 1000 time values in the first column and corresponding pressure values in the second column. But the data gets extrapolated. How do I avoid this.
Thanks in advance

Answers (1)

Titus Edelhofer
Titus Edelhofer on 23 Sep 2014
Hi,
I guess upgrading is not an option? Starting with 2010b you can choose whether to hold the last value or extrapolate. There are some workarounds I could think of:
  • Read the data e.g. in the preload or start function, "manipulate", and use the from workspace block.
  • Modify the data in the .mat file to include another data point with the same value as the last one.
  • Use some switch construct to use a constant value once simulation time passed last time point.
Titus
  2 Comments
Sowmya
Sowmya on 24 Sep 2014
Hi! Titus,
Thank you so much for your reply.
I tried 'from file' block with 2011a. But the data does get interpolated within time range. I will just explain to you what exactly I am looking for.
Suppose I have 10 samples of pressure data with time in a .mat file. The format is: I have 10 samples of time in the first column i.e. 1,2,3,4,5,6,7,8,9,10.
I have 10 samples of pressure data at the corresponding time i.e. 10,20,30,40,50,60,70,80,90,100.
Now I want to transmit this data serially one after another. i.e first 10 should be displayed. Next 20 should be displayed and so on. so basically when we observe the display, the data should change from 10 to 20 to 30 to 40 and so on.
This is possible with 'from workspace' block. But since I have to transmit the data to a real time system, it gives an error when I use the 'from workspace ' block.
That is the reason, I included an embedded matlab function block with the code that accepts data from the file one by one and outputs it.
But now , I am stuck again since the data gets interpolated and is not exactly the same data that i want to transmit. I want exactly the same data as in my file to get transmitted.
Is there any other way to transmit data or if i have to use from file block, then how to avoid interpolation of data within time range.
Thanks once again. Hope you will be able to help me with a solution.
sowmya
Titus Edelhofer
Titus Edelhofer on 25 Sep 2014
O.k., this explains it. If I understand you correctly, you only have to switch the parameter "Data interpolation within time range:" on the from file block parameters from "Linear interpolation" to "Zero order hold", which does exactly this: keep the output constant until the value changes.
Titus

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!