Python Forum
Convert Python code to MATLAB code
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Convert Python code to MATLAB code
#1
How can I convert Python code to MATLAB code?
Reply
#2
By working hard I guess. I don't think there is an automated translator.
Larz60+ and ndc85430 like this post
Reply
#3
(Dec-29-2022, 06:26 PM)Gribouillis Wrote: I don't think there is an automated translator.
Should maybe not mention but AI🎭 is starting to get better in many ways.
import numpy as np

arr2 = np.array([[1, 2, 3], [4, 5, 6]])
for idx, x in np.ndenumerate(arr2):
  print(idx, x)
snippsat Wrote:can you translate to mathlab?
ChatGPT Wrote:Sure! Here is how you could translate the code you provided to MATLAB:
arr2 = [1, 2, 3; 4, 5, 6]; % Create 2D array
for idx = 1:numel(arr2) % Iterate over elements of the array
    [i, j] = ind2sub(size(arr2), idx); % Convert linear index to subscript index
    x = arr2(i, j); % Get element value
    fprintf('(%d, %d) %d\n', i, j, x); % Print indices and element value
end
Don't even complain about effort as we many times do Wink
Gribouillis and Larz60+ like this post
Reply
#4
(Dec-29-2022, 07:38 PM)snippsat Wrote: Should maybe not mention but AI🎭 is starting to get better in many ways
This is quite impressive. I wonder how it works. And also what it can do and what it cannot do.
Reply
#5
Gribouillis Wrote:This is quite impressive. I wonder how it works. And also what it can do and what it cannot do.
I think you might reach these guys by using this little thing
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Can you recommend me a vps that will run api python code? SuchUmami 2 1,026 Aug-16-2023, 02:21 PM
Last Post: snippsat
  Incredible stability of Python code Gribouillis 1 701 Jun-25-2023, 10:14 PM
Last Post: Larz60+
  shortening Python code Skaperen 12 2,478 Oct-23-2022, 10:54 PM
Last Post: Skaperen
  looking for code that substitues parts of python code Skaperen 0 1,196 Jul-07-2022, 11:34 PM
Last Post: Skaperen
  Accessing Python code & SQL datbase from other pc's Extra 1 1,100 Jun-24-2022, 11:30 PM
Last Post: Larz60+
  filtering python code the interpreter reads Skaperen 0 1,176 Feb-02-2022, 08:29 PM
Last Post: Skaperen
  running produced python code Skaperen 6 1,920 Dec-25-2021, 05:52 PM
Last Post: Skaperen
  parsin python code Skaperen 5 2,755 Feb-25-2021, 07:50 PM
Last Post: Skaperen
  Creating Python scripts in Visual Studio Code Sanjish 4 2,618 Dec-22-2020, 12:32 PM
Last Post: snippsat
  parsing Python-like code Skaperen 4 2,416 Nov-06-2020, 12:17 AM
Last Post: Skaperen

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020