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 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
| function pushCalc(obj,event)
try
% On definit figCalc comme l objet parent %
figCalc = get(obj,'parent');
% Recuperation des handlesCalc de figCalc %
handlesCalc = guidata(figCalc);
% Appel de figUCD %
figUCD = getappdata(0,'figUCD');
% Recuperation des handlesUCD de figUCD %
handlesUCD = guidata(figUCD);
% Recuperation Col et TitreCol %
Col = getappdata(0,'Col');
TitreCol = getappdata(0,'TitreCol');
% Recuperation donnees A et B %
A = getappdata(0,'A');
B = getappdata(0,'B');
% Recuperation de Fonction sous forme de string si saisie manuelle
% Sous forme de cell si saisie boutons %
Fonction = get(handlesCalc.editFonction,'string');
% Conversion Fonction cell to string si saisie boutons %
Fonction = char(Fonction);
% Ajout du marqueur fonction (@(x,y)) pour Fonction %
% Si les deux variables sont presentes %
if ismember('A',Fonction) && ismember('B',Fonction)
% Ajout du marqueur %
Fonction = cat(2,'@(x,y)',Fonction);
% Replacement A et B par x et y %
Fonction = strrep(Fonction,'A','x');
Fonction = strrep(Fonction,'B','y');
% Fonction : string to command operation %
Fonction = str2func(Fonction);
% Calcul de la fonction avec les variables selectionnees %
C = Fonction(A,B);
% Si seulement une seule variable %
elseif ismember('A',Fonction) || ismember('B',Fonction)
% Ajout du marqueur %
Fonction = cat(2,'@(x)',Fonction);
% Deux cas : si A existe ou si B existe %
switch ismember('A',Fonction)
case 1
% Remplacement A par x %
Fonction = strrep(Fonction,'A','x');
% Fonction : string to command operation %
Fonction = str2func(Fonction);
% Calcul de la fonction avec la variable selectionnee %
C = Fonction(A);
case 0
% Remplacement B par x %
Fonction = strrep(Fonction,'B','x');
% Fonction : string to command operation %
Fonction = str2func(Fonction);
% Calcul de la fonction avec la variable selectionnee %
C = Fonction(B);
end
end
% Recuperation nom nouvelle variable %
NvelleVar = get(handlesCalc.editNomVar,'string');
% Conversion string vers cell pour enregistrement dans structure Col %
NvelleVar = cellstr(NvelleVar);
% Ajout de C dans Col %
Col.(NvelleVar{1}) = C;
% Ajout nom NvelleVar dans TitreCol %
TitreCol = [TitreCol,NvelleVar];
% Enregistrement nouveau Col et TitreCol %
setappdata(0,'Col',Col);
setappdata(0,'TitreCol',TitreCol);
% Actualisation TitreCol sur UCD %
set(handlesUCD.listX,'string',TitreCol);
set(handlesUCD.listY,'string',TitreCol);
% Fermeture Calculatrice %
close
catch Err
% Message erreur si pas de nom nvelle variable %
if (strcmp(Err.identifier,'MATLAB:AddField:InvalidFieldName'))
MsgErr = sprintf('%s\n%s',...
'Error:',...
'New variable requires a name.');
set(handlesUCD.editMsgErr,'string',MsgErr);
end
% Message erreur si fonction pas renseignee %
if isempty(get(handlesCalc.editFonction,'String'))
MsgErr = sprintf('%s\n%s',...
'Error:',...
'Function not defined.');
set(handlesUCD.editMsgErr,'string',MsgErr);
end
end |
Partager