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
  Best way to learn how to code in python Q890 4 71 Jun-03-2026, 02:45 PM
Last Post: phpjunkie
  Can you recommend me a vps that will run api python code? SuchUmami 2 2,695 Aug-16-2023, 02:21 PM
Last Post: snippsat
  Incredible stability of Python code Gribouillis 1 1,969 Jun-25-2023, 10:14 PM
Last Post: Larz60+
  shortening Python code Skaperen 12 7,256 Oct-23-2022, 10:54 PM
Last Post: Skaperen
  looking for code that substitues parts of python code Skaperen 0 1,942 Jul-07-2022, 11:34 PM
Last Post: Skaperen
  Accessing Python code & SQL datbase from other pc's Extra 1 2,226 Jun-24-2022, 11:30 PM
Last Post: Larz60+
  filtering python code the interpreter reads Skaperen 0 2,150 Feb-02-2022, 08:29 PM
Last Post: Skaperen
  running produced python code Skaperen 6 4,191 Dec-25-2021, 05:52 PM
Last Post: Skaperen
  parsin python code Skaperen 5 4,930 Feb-25-2021, 07:50 PM
Last Post: Skaperen
  Creating Python scripts in Visual Studio Code Sanjish 4 4,574 Dec-22-2020, 12:32 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

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