How to read results from EPANET file in MATLAB

Hi there,

I have done my water distribution system simulation in EPANET and succesfully obtained the results of pressure, demand, velocity, etc and saved in .rpt file. Next, I wanted to export it to MATLAB for further optimization analysis.

Currently, I able to run the water network input file (.inp) in MATLAB using EPANET-MATLAB toolkit.

d = epanet(‘shortnet.inp’);

p = plot(d)

My problem now is how to link up the .inp and the .rpt file? Any suggestion or idea? Thanks in advance!

I also have the same step and want to know the same
If you get it please share with me also
Could you share the epanet matlab tool kit
THANKS

Hi Aswathyvenu,

Sure thing!

I downloaded the EPANET-MATLAB toolkit from here

And this link helps a lot in guiding how to use EPANET-MATLAB toolkit

hi,

you can select that out put of the simulation to be save as you like (e.g., inp, txt,…)

please see the ENsaveinpfile.

Or you see the parameters such as demand, pressure ,… in your work space.

Hi Jafariasl,

Thanks for your response.
The one that you mentioned is if the results saved in EPANET, right?

What if I already exported my network.inp and run in MATLAB, how can I get the results in MATLAB without depending on EPANET result file? Sorry, I still don’t get the real picture yet.

Hello,
I explained in following to you an example.
step 1:
loadlibrary(‘epanet2’,‘epanet2’);
calllib(‘epanet2’,‘ENopen’,‘Net1.inp’,‘Net1.rpt’,’’);
for example assigning the diameters of the link (e.g., D=254 mm)
calllib(‘epanet2’,‘ENsetlinkvalue’,1,0,D)…1 is link number
step 2:
%% analyzing the network
calllib(‘epanet2’,‘ENsolveH’);
calllib(‘epanet2’,‘ENsolveQ’);
calllib(‘epanet2’,‘ENreport’);
step 3:
than you can see the results…
[a h2]=calllib(‘epanet2’,‘ENgetnodevalue’,1,11,0);…1 is node number, 11 is param code of pressure…and h2 is a matrixs that the value of pressure will be save in it.
[a v1]=calllib(‘epanet2’,‘ENgetlinkvalue’,1,9,0);…1 is link number, 9 is param code of velocity…and v1 is a matrixs that the value of velocity will be save in it.

regards

1 Like

Hi @Zaura,

You try the example:

start_toolkit;

d = epanet(‘Net1.inp’);

% Hydraulic analysis (contains events)
results = d.getComputedHydraulicTimeSeries

% Hydraulic and Quality analysis using epanet2d.exe binary file (ignores events)
results2 = d.getComputedTimeSeries

% Quality analysis (contains events)
quality_results = d.getComputedQualityTimeSeries

Also, you can check the folder examples.
>>help d.plot;
Newest version pre-released is here (included all new functions of EPANET): https://github.com/OpenWaterAnalytics/EPANET-Matlab-Toolkit/tree/dev-2.2-edit

thank you for your response

hello all
while using epanet matlab tool kit I got the following error screen


I use the you tube video for the above and error occur in between the steps

Hi
Please set paths again.
you should use this line ( path(path,‘D:\latest project\my code’)) in the start of your`s codes ( mycode).

Big thanks @Mariosmsk!

Thanks alot @Jafariasl!

@Jafariasl
Thanks for your response
But I don’t get


I do the above
and get the below screen

I also try the below step according to the below link
https://www.mathworks.com/help/matlab/matlab_env/add-remove-or-reorder-folders-on-the-search-path.html
Home-environment-path and select c:\Users\ASWATHY\Desktop\MyCode and then save and close
Once in a while it shows the below screen also

hello
you should use (loadlibrary(‘epanet2’,‘epanet2’):wink: after set paths.

1 Like

@Jafariasl ok, I will😀

@Jafariasl
You mean
Instead of d = epanet( net1.inp)
I use the above
Isn’t it…?
Am probably first time in programming area. That’s why keep on asking you…sorry for that
Thanks all of you for the response :hugs:

Hi @aswathyvenu,

Maybe you need to install the MinGW-w64 compiler

@ aswathyvenu
after you did set paths, you should load epanet library by this means (loadlibrary(‘epanet2’,‘epanet2’)),
DO you have MinGW or Microsoft Visual Studio on your PC?

@Jafariasl, @Mariosmsk
Sir, First of all thanks for your response


When I follow the steps in video the same error occur and the script also attached below


@Mariosmsk
Sir, when I use the following step, I install MinGW-w64 compiler, but get the following error screen


Thank you

To check if the compiler installed.

mex -setup

Anyway, you can try the following example without loadlibrary(‘epanet2’,‘epanet2’):

start_toolkit;

% Load a network.
d = epanet('Net1.inp');

d.getNodeElevations

d.unload;

Regards,
Marios