How do I change this code to Python?

I can only use MATLAB through my university's Exceed onDemand, and therefore there are certain limitations of what I can do. I'm thinking therefore to change to Python as it's free and I have it installed on my Macbook Pro. This is the code I want to change to python syntax:
function experiment_code
a=round(rand(1,10)*2);
b(find(a<0.5))=1;
b=b+1;
%FILES FOR VISUAL BASELINE EXPERIMENT
I1 = imread('1img.jpg');
I2 = imread('2img.jpg');
I3 = imread('3img.jpg');
I4 = imread('4img.jpg');
I5 = imread('5img.jpg');
I6 = imread('6img.jpg');
I7 = imread('7img.jpg');
I8 = imread('8img.jpg');
I9 = imread('9img.jpg');
I10 = imread('10img.jpg');
I11 = imread('11img.jpg');
I12 = imread('12img.jpg');
I13 = imread('13img.jpg');
I14 = imread('14img.jpg');
I15 = imread('15img.jpg');
I16 = imread('16img.jpg');
%FILES FOR AUDITORY EXPERIMENT
[y1,Fs1,NBITS1]=wavread('1sound.wav');
[y2,Fs2,NBITS2]=wavread('2sound.wav');
[y3,Fs3,NBITS3]=wavread('3sound.wav');
[y4,Fs4,NBITS4]=wavread('4sound.wav');
[y5,Fs5,NBITS5]=wavread('5sound.wav');
[y6,Fs6,NBITS6]=wavread('6sound.wav');
[y7,Fs7,NBITS7]=wavread('7sound.wav');
[y8,Fs8,NBITS8]=wavread('8sound.wav');
[y9,Fs9,NBITS9]=wavread('9sound.wav');
[y10,Fs10,NBITS10]=wavread('10sound.wav');
[y11,Fs11,NBITS11]=wavread('11sound.wav');
[y12,Fs12,NBITS12]=wavread('12sound.wav');
[y13,Fs13,NBITS13]=wavread('13sound.wav');
[y14,Fs14,NBITS14]=wavread('14sound.wav');
[y15,Fs15,NBITS15]=wavread('15sound.wav');
[y16,Fs16,NBITS16]=wavread('16sound.wav');
%EXPERIMENT TRAINING & TESTS
for j=1:4
numpatterns=2^j;
FAILED=true;NumBlocks(j)=0;
while FAILED==true;
% training block
NumBlocks(j)=NumBlocks(j)+1;
b = rand(1,numpatterns);
[junk,shuffled]=sort(b);
%VISUAL BASELINE EXPERIMENT
for i=1:numpatterns
pattern=shuffled(i);
figure(pattern);
eval(['imshow(I',num2str(pattern),')']);
eval(['sound(y',num2str(pattern) ,' ,Fs',num2str(pattern) ,',NBITS',num2str(pattern) ,')']);
junk=input('hit a key to continue');close(pattern);
end%training
%test
b = rand(1,numpatterns);[junk,shuffled]=sort(b);
numtests=4
if numpatterns==2;numtests=2;end
for k=1:numtests
pattern=shuffled(k);
truth(k)=pattern;
figure(100)
eval(['imshow(I',num2str(pattern),')']);
eval(['sound(y',num2str(pattern) ,' ,Fs',num2str(pattern) ,',NBITS',num2str(pattern) ,')']);
answer(k)=input('Which shape?');
end%test
if answer==truth;FAILED=false;end
end%a training block
end%2 4 8 16
NumBlocks'
Thanks!

1 commentaire

George
George le 2 Nov 2015
Modifié(e) : Stephen23 le 2 Nov 2015
I think this is not the right place for python question , you can ask on stackoverflow http://stackoverflow.com The community there includes python users as well, which may be able to help

Connectez-vous pour commenter.

Réponses (0)

Catégories

Produits

Tags

Aucun tag saisi pour le moment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by