# How to convert the MATLAB code into the Python?

3,859 views (last 30 days)
Milind dilipkumar Patel on 26 Oct 2018
Answered: Arash Rabbani on 26 May 2022
Hello, I have a matlab code for the quantitative differential phase contrast imaging and the code is very big and complicated as well. But the problem is the institute where I am working does not allow to use matlab and they have python and LabVIEW, so I would like to convert the matlab code to python or someone knows how to run the matlab code in python then it also be very helpful.
I have attached the main code.
Thank you.
Deepu S S on 5 Jan 2022
To convert Matlab to python, a tool named SMOP (Small Matlab and Octave to Python Compiler) is used. This tool is capable of understanding basic Matlab code and then parsing it to python. Although there are always limitations to every tool, this tool works best for small-level codes.

madhan ravi on 26 Oct 2018
Edited: madhan ravi on 26 Oct 2018
You can use numpy framework which contains matlab libraries.
See cheat sheet , I faced similar situation as you but raged with the cheat sheet, good luck!

Gurubasava Bhure on 24 Jul 2021
clc() clear(mstring('all')) close(mstring('all')) # Generating the bit pattern with each bit 20 samples long b = round(rand(1, 30)) pattern = mcat([]) for k in mslice[1:30]: if b(1, k) == 0: sig = -ones(1, 20) else: sig = ones(1, 20) end
pattern = mcat([pattern, sig])
end
subplot(4, 1, 1)
plot(pattern)
axis(mcat([-1, 600 - 1.5, 1.5]))
title(mstring('Original Bit Sequence'))
# Generating the pseudo random bit pattern for spreading
d = round(rand(1, 120))
pn_seq = mcat([])
carrier = mcat([])
t = mcat([mslice[0:2 * pi / 4:2 * pi]])# Creating 5 samples for one cosine
for k in mslice[1:120]:
if d(1, k) == 0:
sig = -ones(1, 5)
else:
sig = ones(1, 5)
end
c = cos(t)
carrier = mcat([carrier, c])
pn_seq = mcat([pn_seq, sig])
Samuel Gray on 3 May 2022
...see?
So it's like other forums in that way, especially like YT forums, but there's no obvious indication of that...
But if you've spent most of your formative years posting on forums that support @ replies, you'd just do that by rote and find that it works. I did find it by typing in @ (for another reason) and as you see if you try that, all sorts of user names will pop up.
So it's dangerous to assume that something is or is not a certain way because quite often it's just a matter of your background and your willingness to experiment and do some research on Google. Some people like that about Life and some don't.

Arthi Raj on 29 Mar 2022
Edited: Walter Roberson on 3 May 2022
%clc;
clear;
close all;
% [filename, pathname] = uigetfile('*.jpg', 'CHOOSE A IMAGE');
% A=imcrop(A);
A=imresize(A,[256 256]);
A=immultiply(A,1.5);
figure;imshow(A);impixelinfo;
ro=size(A,1);
co=size(A,2);
H=0;
for n=1:ro
for m=1:co
R=A(n,m,1);
G=A(n,m,2);
B=A(n,m,3);
if(R>180&&G<200&&G>150&&B<100)
H=H+1;
end
end
end

Arash Rabbani on 26 May 2022
You may want to check these tutorials on how to convert a code from MATLAB to python.