Home Questions Using a .mat dataset for a KinArm model

Using a .mat dataset for a KinArm model

DWQA QuestionsCategory: KINARM End-Point LabUsing a .mat dataset for a KinArm model
Rauf Iftikhar asked 1 year ago
I have a .mat dataset (2 columns) that I wish to interpolate and create a Simulink lookup table. This lookup table would then provide output loads on the KinArm based on input position data. In simulink, running such a model requires loading the dataset into the MATLAB workspace. Is it possible to reference an external file within an .mldatx file? If the .mat file is in the task folder, will the task be able to run? Thanks, Rauf
1 Answers
Koloman Varady Staff answered 1 year ago

Hi Rauf,

It is possible for the task, while running in real time, to read from a file (1 to 5 files, in fact). The files have to be converted to binary format first though.

Our sample task here https://kinarm.com/task/input-file-example-drawing-hand-paths/ shows how to load and read a file in a task. The sample tasks also includes a demo .M file for creating a binary file out of a vector of doubles.

Let me know if you have any questions.

Cheers,
Koloman

Rauf Iftikhar replied 1 year ago

Thanks for this answer. If I have multiple matrices stored in the .mat file, how will I know how to index into each specific one? How can I see the structure of the converted data?

Koloman Varady Staff replied 1 year ago

Since you create the binary format file, it’ll be up to you what the structure is. In the example, the binary file is just singles and they’re read one at a time per ms. You can have up to 5 files, so if you have rows you could put each in a file. If not, you could do column-major or row-major format.

Rauf Iftikhar replied 1 year ago

Currently I take a .mat file of 3 2 column matrixes and convert it into 3 corresponding binary .dat files with each value stored as a single (float32) so that I can output both values from each row in each byte. In my model I then unpack and convert. If I want the first column to be the xdat/breakpoints for a lookup table and the second column to be the ydat/table data, how can I achieve this? I tried to use a dynamic lookup table, but because the input file only reads a byte at a time we only pass a single value to the xdat and ydat at a time, which causes an error (“breakpoint and table port cannot be scalar”). I want to load the entire data set and then pass the respective vectors to a lookup table, not pass each individual value as it is read in. Is this possible?

Koloman Varady Staff replied 1 year ago

It depends on how big your matrices are. In the example task, the reading doesn’t start until the Go button is pressed in Dexterit-E (this is because it is an enabled subsystem that is taking a signal from Stateflow, which doesn’t start to execute until the Go button is pressed. If you remove that enable, the code will start to execute as soon the task is loaded (when you double click or select the task in Dexterit-E or when it finishes executing, it will also reload). So you could have the task load, wait 2 seconds, and have 6000 elements from your matrices loaded.