Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Read Dynamically Set Arrays from .mat File #40

Closed
moored6 opened this issue Mar 10, 2022 · 1 comment
Closed

Read Dynamically Set Arrays from .mat File #40

moored6 opened this issue Mar 10, 2022 · 1 comment

Comments

@moored6
Copy link

moored6 commented Mar 10, 2022

Hi there,

I'd like to load a dynamically sized array from a Matlab file. This is a similar issue to issue #34.

Below is a minimal example that fails. It looks like Dymola fails to expand the variable.

model MATTest2 "MAT-file read test"
  extends Modelica.Icons.Example;
  inner parameter ExternData.MATFile dataSource(fileName=Modelica.Utilities.Files.loadResource("modelica://ExternData/Resources/Examples/test_v7.3.mat")) "MAT file" annotation(Placement(transformation(extent={{-80,60},{-60,80}})));
  final parameter Integer m = dataSource.getArrayRows2D("table1") "Number of rows in 2D array";
  parameter Real matTable[:,:] = dataSource.getRealArray2D("table1", m, 2);
  annotation(experiment(StopTime=1),
    Documentation(info="<html><p>This example model reads the table parameter from variable table1 of the HDF5-based MAT-file <a href=\"modelica://ExternData/Resources/Examples/test_v7.3.mat\">test_v7.3.mat</a>. The table parameter is read as Real array of dimension 3x2 by function <a href=\"modelica://ExternData.dataSource.getRealArray2D\">ExternData.dataSource.getRealArray2D</a>. The read parameter is assigned by a parameter binding to the appropriate model parameter.</p></html>"));
end MATTest2;

I've tested this in Dymola 2022x, and I get an error stating:
Failed to expand the variable matTable
and its definition equation:
dataSource.getRealArray2D_Unique'"dataSource"'(
"table1",
m,
2,
dataSource.mat)

Is it possible to use parameter Real matTable[:,:] = dataSource.getRealArray2D(tableName, m, 2); instead of parameter Real matTable[:,:] = dataSource.getRealArray2D(tableName, 3, 2);

Is there a workaround for this? Any help here would be appreciated. Thank you for your time.

@moored6 moored6 closed this as completed Mar 11, 2022
@beutlich
Copy link
Contributor

beutlich commented Mar 12, 2022

I guess you figured out yourself how to circumvent the issue. See also #39 (comment).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants