Bonsoir à tous;
je sais comment créer une fonction MATLAB et l'appliquer sur des éléments, le problème est que je n'arrive pas à écrire une fonction pour l'appliquer à un vecteur quelconque,,,...
les détails:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
| num_categ=0:10;
nb_symb_total=0;
for i=1:length(num_categ)
nb_symb_total=nb_symb_total+sum(2^(num_categ(i)));
end
nb_symb_total
% Calcule des probabilités de chaque catégorie
for j=1:length(num_categ)
prob(j)=(2.^(num_categ(j)))/nb_symb_total;
end
prob=prob(11:-1:1)
dict=huffmandict(num_categ,prob);
for i=1:length(num_categ)
dict{i,:};
end
dict
%% /////////////////////////////////////////////////////////////////////////
% teste Codage DC
v=[1];
%% Extraire les numéro des catégories:
for s=1:length(v)
if (v(s)==0)
extnum_categ(s)=0;
else
extnum_categ(s)=fix(log2(abs(v(s))))+1;
end
end
extnum_categ
%% Créations des vecteurs pour les catégories correspondants:
stockdc=1;
index_stock=0;
g=(2.^(extnum_categ))./2
for s=1:length(v)
% Créations des valeurs positifs
valpositif=[];
valnegatif=[];
valpositif(1)=g(s);
nbunajout=(2^(extnum_categ(s)-1));
for i=2:nbunajout
valpositif(i)=valpositif(i-1)+1;
end
% Créations des valeurs négatifs
for t=1:length(valpositif)
valnegatif(t)=valpositif(length(valpositif)+1-t)*(-1);
end
%La Concaténation:
concat=[];
if (v(s)==0)
concat=0;
else
for x=1:length(valpositif)
concat(x)=valnegatif(x);
end
for y=length(valpositif)+1:(length(valpositif)*2)
concat(y)=valpositif(y-length(valpositif));
end
end
concat
% Chercher la position du symbole dans la table DC:
position=0;
for o=1:length(concat)
if (v(s)==concat(o))
position=o;
end
end
position
%% Codage du symbole DC: codeHuffman categorie + code position
code_categ=[]; % Initialisation
code_categ=[dict{extnum_categ(s)+1,2}]
code_pos=[]; % Initialisation
if (v(s)==0)
code_pos=0;
else
code_pos=de2bi(position-1,extnum_categ(s),'left-msb');
end
code_pos
code_symb_dc=[]
for e=1:length(code_categ)
code_symb_dc(e)=code_categ(e);
end
for f=length(code_categ)+1:(length(code_categ)+length(code_pos))
code_symb_dc(f)=code_pos(f-length(code_categ));
end
code_symb_dc
for h=stockdc:stockdc+length(code_symb_dc)-1
JPEG_DC(h)=code_symb_dc(h-(index_stock));
end
stockdc=length(JPEG_DC)+1;
index_stock=length(JPEG_DC);
end
JPEG_DC |
je veux résumer tous ce calcule dans une fonction par exemple:
function JPEG_DC=convdc(vect) % vect=vecteur quelconque
Des idées !
Merci à l'avance
Partager