Ok this is a long one.
I have a MATLAB code where I read data from the text file and use that data to conduct some analysis. The text file has 6 columns and each column has a label. In the code, I have to use data from a particular column and use interpolation to find values. Some of the lines that I use in this MATLAB code are-
SubProp_e_intlow=SubProp(SubProp.Pressure==P_e_int1ow,:);
h1=interp1(SatProp.Pressure,SatProp.LiqEnth,P_cond);
(SubProp and Sat Prop are the tables loaded from the text files, pressure is the column in both the tables. First line is used to seperate the table into smaller tables depending on the working pressure, to further use interpolation function on these smaller tables)
This code works perfectly fine.
My problem is trying to make this work in Simulink. I have to create a matlab function block and use this code or similar logic. There are several problems that I ran into:
- My first problem was reading the data into the matlab function block. I don't know how to read from a text file. Function readtable doesn't work directly, so I include code.extrinsic(readtable), but this didn't work and I ran into many problems.
- Then I tried converting txt data file to csv file and use 'from file' block to read this data. But this divided the columns into seperate tables/outputs (I think), so I had trouble using the same interp1 function as above. So I tried something else in a test code, which you can see in the picture below
. where the code in matlab function is
function [P_L_intlow,P_L_intup,hi] = fcn(P_H,P_L,a,b,c,d,e,f)
P_H_int1ow=floor((P_H)/10000)*10000;
P_H_intup=ceil((P_H)/10000)*10000;
P_L_intlow=floor((P_L)/10000)*10000;
P_L_intup=ceil((P_L)/10000)*10000;
h1=(((hj-hi)/(P_L_intup-P_L_intlow))*(P_L-P_L_intlow))+hi;
Here the error I am getting is related hi - Data 'hi' is inferred as a variable size matrix, while its properties in the Model Explorer specify its size as inherited or fixed. Please check the 'Variable Size' check box and specify the upper bounds in the size field. So I change it to variable size and I am getting error saying there is Size Mismatch.
Honestly, I don't know how to approach this. I want to be able to read the data into the MATLAB function all at once, and then use that data in the same way I used in the MATLAB code.
Any help would be appreciated.