MATLAB to python conversion
8 次查看(过去 30 天)
显示 更早的评论
I have a matlab script and its supporting function scripts. my code uses Image processing toolbox. I want to convert all to python. how can I do it ? And my python code should run independent of MATLAB. Any help .
采纳的回答
ES
2018-5-24
编辑:KSSV
2018-5-24
I have used libermate for matlab to python conversion. It is awesome!
2 个评论
Stephen Nagy
2018-7-2
I see linux commands but I'm in windows server 2012r2. Are there windows installs too or am I just missing something?
更多回答(2 个)
Pranav Chaudhari
2021-4-1
function makeSong()
%% By YI-WEN CHEN, 2018 / Jarvus Studio
% 1. According to Piano key frequencies (https://en.wikipedia.org/wiki/Piano_key_frequencies),
% we can create its pitch by fundamental frequency.
% 2. Play twingle twingle little star as an example.
% Sessions Overview:
% http://jarvus.dragonbeef.net/note/noteAudio.php
fs = 44100;
% rest
zero = rest(4,fs); % 1.0 sec
zeroh = rest(8,fs); % 0.5 sec
zerohh = rest(16,fs); % 0.25 sec
% eighth note as 0.5 sec
do = key(52,8,fs); %do 1
re = key(54,8,fs); %re 2
mi = key(56,8,fs); %mi 3
fa = key(57,8,fs); %fa 4
so = key(59,8,fs); %so 5
la = key(61,8,fs); %la 6
si = key(63,8,fs); %si 7
% quarter note as 1 sec
do_4 = key(52,4,fs); %do 1
re_4 = key(54,4,fs); %re 2
mi_4 = key(56,4,fs); %mi 3
fa_4 = key(57,4,fs); %fa 4
so_4 = key(59,4,fs); %so 5
la_4 = key(61,4,fs); %la 6
si_4 = key(63,4,fs); %si 7
% make a song
line1 = [ do do so so la la so_4];
line2 = [ fa fa mi mi re re do_4];
line3 = [ so so fa fa mi mi re_4];
line4 = [ so so fa fa mi mi re_4];
line5 = [ do do so so la la so_4];
line6 = [ fa fa mi mi re re do_4];
song = [line1 line2 line3 line4 line5 line6];
plot(song)
sound(song,fs,24);
%audiowrite('star.wav',song,fs,'BitsPerSample',32);
function wave = key(p, n, fs)
t = 0:1/fs:4/n;
idx = 440*2^((p-49)/12);
% method 1 - orginal
wave = (sin(2*pi*idx*t));
% method 2 - exponential decreasing
% tt = 4/n:-1/fs:0;
% wave = (sin(2*pi*idx*t)).*exp(tt);
% wave = wave./max(wave);
% method 3 - triangle decreasing
% mid = (t(1)+t(end))/2;
% tri = -(abs(t-mid)-mid);
% tri = tri./max(tri);
% wave = (sin(2*pi*idx*t)).*tri;
plot(wave)
function wave = rest(n,fs)
t = 0:1/fs:4/n;
tt = 4/n:-1/fs:0;
wave = 0*sin(2*pi*t).*exp(tt);
0 个评论
shubham patel
2021-8-16
clc
e1=input('Enter f(x)=','s');
f=inline(e1);
a=input('Enter a=');
n=input('iterations=');
b=input('Enter b=');
while (f(a)*f(b)>0)
disp('wrong guesses');
a=input('Enter Initial Guess a=');
b=input('Enter Initial Guess b=');
end
fprintf('\n Itr. No.\t a\t\t b \t\t\t\t xr\t\t Error');
i=1;
xr=(a+b)/2;
xrold=a;
fprintf('\n %d \t\t %f\t %f \t %f\t %f',i,a,b,xr,abs((xr-xrold)/xr));
for i=2:n
if(f(xr)*f(b)<0)
a=xr;
else
b=xr;
end
xrold=xr;
xr=(a+b)/2;
fprintf('\n %d \t\t %f\t %f \t %f\t %f',i,a,b,xr,abs((xr-xrold)/xr));
end
i=i+1;
fprintf('\n\tRoot of equation is=%f',xr);
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Call Python from MATLAB 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!