define a function like python
이전 댓글 표시
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
Rik
2022년 2월 17일
What is your question? If you have trouble with Matlab basics you may consider doing the Onramp tutorial (which is provided for free by Mathworks).
Walter Roberson
2022년 2월 17일
Opps, sorry, it did not keep the spacing properly when I converted it to code :(
Walter Roberson
2022년 2월 17일
Okay, could you explain what you mean by "write like this in Matlab" ?
Do you mean that you want to be able to have code that in the middle of a .m file, complete with having lines end with : and complete with using # as a comma?
Do you mean that you want to be able to create Python code in a .py file and refer to it from MATLAB without going through the python objects that would normallty be needed to get Python to execute it?
bahar vojdani
2022년 2월 18일
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
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
2022년 2월 19일
bahar vojdani
2022년 5월 5일
Walter Roberson
2022년 5월 5일
https://www.mathworks.com/matlabcentral/answers/9957-using-net-filesystemwatcher-to-listen-for-new-files#answer_13710
카테고리
도움말 센터 및 File Exchange에서 Integration with Online Platforms에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!