필터 지우기
필터 지우기

Translate python into matlab

조회 수: 9 (최근 30일)
Marcus Jensen
Marcus Jensen 2021년 8월 16일
편집: Wan Ji 2021년 8월 16일
Hi all,
I have a solution for a task I have to do, but the solution is written and works with python. Now I am asking, if any of you know a way, this could be written in matlab? I am very new to matlab, and therefore I am unable to figure it out myself. The most difficulties arise, when I have to find a solution to pythons enumerate function... Thank you in advance!
The code:
data = np.array([[10, -3, 10, 7, 0, 12],
[12, 12, 12, 10, 0, 12],
[7, 7, 10, 10, 0, 10],
[7, 4, 7, 7, 0, 12],
[-3, 4, 7, 4, 4, 12],
[7, 4, 4, 4, 0, 12]])
jitter_min = -0.1
jitter_max = 0.1
for a,grades in enumerate(data):
x = a*np.ones(len(grades)) + (jitter_max-jitter_min)*np.random.random(size=len(grades))+jitter_min
plt.plot(x, grades, 'o', label='Assignment #{:d}'.format(a), clip_on=False)
plt.xlabel('Assignments')
plt.ylabel('Grades')

답변 (1개)

Wan Ji
Wan Ji 2021년 8월 16일
편집: Wan Ji 2021년 8월 16일
We firstly make data a matrix. Each row is named grades, and the row number is a. Then python code can be tranlated to matlab one:
data = [[10, -3, 10, 7, 0, 12];
[12, 12, 12, 10, 0, 12];
[7, 7, 10, 10, 0, 10];
[7, 4, 7, 7, 0, 12];
[-3, 4, 7, 4, 4, 12];
[7, 4, 4, 4, 0, 12]];
jitter_min = -0.1;
jitter_max = 0.1;
for a = 1:1:size(data,1)
grades = data(a,:);
x = (a-1)*ones(size(grades)) + (jitter_max-jitter_min)*rand(size(grades))+jitter_min;
plot(x, grades, 'o')
hold on
end
xlabel('Assignments')
ylabel('Grades')

카테고리

Help CenterFile Exchange에서 Call Python from MATLAB에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by