Openseespy link to Matlab

Forum for OpenSees users to post questions, comments, etc. on the use of the OpenSees interpreter, OpenSees.exe

Moderators: silvia, selimgunay, Moderators

Post Reply
azamabdollahi
Posts: 4
Joined: Thu Oct 01, 2015 6:27 am
Location: university of sistan and bluchestan

Openseespy link to Matlab

Post by azamabdollahi »

Hi,

I work with OpenSeesPy recently.I would like to link MATLAB to OpenSeespy. There are 5 parameters in Openseespy that they should read from Matlab and then the output from OpenSeespy import to Matlab. Could you help me how to call from Matlab and OpenSeespy? If you have any sample program that you do in this issue please let me know.

p1,p2,p3,p4,p5 (Matlab)------->OpenseesPy
output(OpenSeesPy)--------->Matlab

Thanks,
gswarup
Posts: 6
Joined: Mon Jul 29, 2013 9:46 am
Location: BESU, Shibpur

Re: Openseespy link to Matlab

Post by gswarup »

Hello,

You can save the matlab variables in a *.mat file, say it's a matrix (or array) myvar = (p1, p2, p3, p4, p5) and saved in 'myvar.mat'. From python you can then load this mat file

from scipy.io import loadmat, savemat
var = loadmat('myvar.mat')
# 'var' will be a 'dict' {}, so extract your matrix
myvar=var['myvar']

then you can extract p1,p2,... by python indexing and run opensees using those.

and after analysis you can save them back in a mat file. say 'out' is your output variable,

D={} #define a 'dict'
D['out']=out

savemat('D',out)

output variable will be saved in 'D.mat' file. Now you can use that in matlab. you can perform this task just by switching between matlab and python windows.

or otherwise you can call matlab engine from python. see 'Matlab API for Python' in Matlab help. But the easiest way would be the previous one.
azamabdollahi
Posts: 4
Joined: Thu Oct 01, 2015 6:27 am
Location: university of sistan and bluchestan

Re: Openseespy link to Matlab

Post by azamabdollahi »

gswarup wrote:
> Hello,
>
> You can save the matlab variables in a *.mat file, say it's a matrix (or
> array) myvar = (p1, p2, p3, p4, p5) and saved in 'myvar.mat'. From python
> you can then load this mat file
>
> from scipy.io import loadmat, savemat
> var = loadmat('myvar.mat')
> # 'var' will be a 'dict' {}, so extract your matrix
> myvar=var['myvar']
>
> then you can extract p1,p2,... by python indexing and run opensees using
> those.
>
> and after analysis you can save them back in a mat file. say 'out' is your
> output variable,
>
> D={} #define a 'dict'
> D['out']=out
>
> savemat('D',out)
>
> output variable will be saved in 'D.mat' file. Now you can use that in
> matlab. you can perform this task just by switching between matlab and
> python windows.
>
> or otherwise you can call matlab engine from python. see 'Matlab API for
> Python' in Matlab help. But the easiest way would be the previous one.

Thank you so much. I installed OpenseesPy via Anaconda. I wrote in Spyder:

import sys
import numpy as np
print("hello")

also wrote in Matlab :

system('python test.py')

when I run Matlab, I have an error:

Traceback (most recent call last):
File "test.py", line 2, in <module>
import numpy as np
ModuleNotFoundError: No module named 'numpy'

I don't know why this error was appeared.
imansalehi
Posts: 11
Joined: Sat Jul 28, 2018 12:05 pm

Re: Openseespy link to Matlab

Post by imansalehi »

Hi
if you want to use directly OpenSees framework in Matlab environment you can use OpenSees.NET
https://www.youtube.com/watch?v=rEDNtXR9RwY


http://opensees.net/
http://opensees.net/blog
azamabdollahi
Posts: 4
Joined: Thu Oct 01, 2015 6:27 am
Location: university of sistan and bluchestan

Re: Openseespy link to Matlab

Post by azamabdollahi »

imansalehi wrote:
> Hi
> if you want to use directly OpenSees framework in Matlab environment you
> can use OpenSees.NET
> https://www.youtube.com/watch?v=rEDNtXR9RwY
>
>
> http://opensees.net/
> http://opensees.net/blog

Hi Iman,
Thank you so much for good point.
Post Reply