필터 지우기
필터 지우기

define a function like python

조회 수: 8 (최근 30일)
bahar vojdani
bahar vojdani 2022년 2월 17일
댓글: Walter Roberson 2022년 5월 5일
Hello all,
I have a fuction in python but I want to write like this in Matlab.
def link_to_grasshopper(x):
# x is a numpy array
# part 1: from jupyter to GH
df = pd.DataFrame(remap(x))
df.to_csv('X.csv')
# wait pls
sleep(120.0)
# part 2: from GH back to jupyter
f = pd.read_csv('Fitness.csv')
return f.values[0][0]
  댓글 수: 5
bahar vojdani
bahar vojdani 2022년 2월 18일
Thanks for helping All in all I wanted to write a function gives some parameters,and creat csv file with parameters and after simulation in other software(sleep time) read file csv an return value of csv file
Image Analyst
Image Analyst 2022년 2월 18일
So did you take what I gave below and try to continue with it? If not, why not? Let's see your latest version of it.

댓글을 달려면 로그인하십시오.

답변 (1개)

Image Analyst
Image Analyst 2022년 2월 17일
Perhaps something like this:
function data = ReadGrasshopperFile(x, fileName1, fileName2)
% x is a numpy array
% part 1: from jupyter to GH
df = pd.DataFrame(remap(x))
% Write to CSV file
writematrix(df, fileName1);
% wait pls
sleep(120.0)
% part 2: from GH back to jupyter
data = readmatrix(fileName);
end
Or maybe at least it's a start, since I'm not really sure what all those things in your Python code are.
  댓글 수: 3
bahar vojdani
bahar vojdani 2022년 5월 5일
hello dear,
I have a python script, but I want to rewrite that in Matlab. Indeed, in python, I used the os module to help me interact with the operating system. 'os.path.getmtime(path)' Return the time of the last modification of the path.
def cost(x):
df1 = pd.DataFrame(x)
fileName = 'output.csv'
originalTime = os.path.getmtime(fileName)
df1.to_csv('inputs.csv')
while(True):
if(os.path.getmtime(fileName) > originalTime):
break
df2 = pd.read_csv('output.csv',memory_map=True)
d = []
for i,j in zip(df1.itertuples(),df2.iteritems()):
t = deepcopy(list(j[1]))
h = deepcopy(list(i))
h.pop(0)
results.loc[len(results.index)] = h + t
t[0] *= -1
d.append(t)
return d
Walter Roberson
Walter Roberson 2022년 5월 5일
https://www.mathworks.com/matlabcentral/answers/9957-using-net-filesystemwatcher-to-listen-for-new-files#answer_13710

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Integration with Online Platforms에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by