I am currently writing a matlab function that I have embedded in a simulink model.
Now when compiling I get the error message that simulink expect indx_p11 to be a scalar but it is a [:?,1] where I use this to extract data slices from the matrix. Similar error messages exist for the other indx_p variables.
Initially the lines with indx_p11 = zeros(1,1) was not present as I hoped to preallocate them and hence fix the dimensions. The error messages were exactly the same.
I have no idea how to fix this.
Can somebody please help?
P.S.: Inside matlab it works as intended. Simulink seems to be stricter here but I don’t know how to solve it.
function indx = GetMtrxInterval(temp,press,property_matrix)
indx = zeros(4,1);
indx_p11 = zeros(1,1);
indx_p12 = zeros(1,1);
indx_p21 = zeros(1,1);
indx_p22 = zeros(1,1);
press_intervals_idx = find(diff(property_matrix(:,2))); % contains indexes of pressure values after which the pressure changes in properties STOFF table
if press >= min(property_matrix(:,2)) && press <= max(property_matrix(:,2))
%find slice of table with max(pressure<press)
indx_p12 = find(press<property_matrix(:,2),1) - 1;
indx_p11 = press_intervals_idx(find(indx_p12==press_intervals_idx,1)-1)+1;
%find slice of table with min(pressure>press)
indx_p21 = indx_p12 + 1;
indx_p22 = press_intervals_idx(find(indx_p12==press_intervals_idx,1)+1);
%find temperature interval for lower pressure slice
if temp >= min(property_matrix(indx_p11:indx_p12,1)) && temp <= max(property_matrix(indx_p11:indx_p12,1))
%find temperature interval for lower pressure slice
if temp == property_matrix(indx_p11,1)
indx_t11 = indx_p11;
indx_t12 = indx_t11+1;
else
indx_t12 = indx_p11 + find(temp<=property_matrix(indx_p11:indx_p12,1),1) - 1;
indx_t11 = indx_t12-1;
end
end
indx = [indx_t11; ...
indx_t12; ...
indx_t21; ...
indx_t22];
end