Python Forum
Convert Python code to MATLAB code - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: General (https://python-forum.io/forum-1.html)
+--- Forum: News and Discussions (https://python-forum.io/forum-31.html)
+--- Thread: Convert Python code to MATLAB code (/thread-39073.html)



Convert Python code to MATLAB code - bitoded - Dec-29-2022

How can I convert Python code to MATLAB code?


RE: Convert Python code to MATLAB code - Gribouillis - Dec-29-2022

By working hard I guess. I don't think there is an automated translator.


RE: Convert Python code to MATLAB code - snippsat - Dec-29-2022

(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


RE: Convert Python code to MATLAB code - Gribouillis - Dec-29-2022

(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.


RE: Convert Python code to MATLAB code - Larz60+ - Dec-30-2022

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