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!