IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

MATLAB Discussion :

récupérer les données d'un fichier que l'on sélectionne [Débutant]


Sujet :

MATLAB

  1. #1
    Membre confirmé
    Homme Profil pro
    Étudiant
    Inscrit en
    Juin 2011
    Messages
    46
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Nord (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Étudiant
    Secteur : Industrie

    Informations forums :
    Inscription : Juin 2011
    Messages : 46
    Par défaut récupérer les données d'un fichier que l'on sélectionne
    bonjour a tous, je suis nouveau sur le site.

    Voila mon petit problème:

    je suis en train de créer une interface GUI qui va afficher plusieurs images.
    Mon problème est que je charge le programme dans OpeningFcn mais a chaque chargement d'image, je doit de nouveau recharger le programme par l'intermédiaire ' uigetfile '.
    J'aimerais donc pouvoir charger le programme une fois dans OpeningFcn et cliquer sur mes différents boutons sans devoir recharger le programme.

    Avez vous une idée pour m'aider?
    Merci beaucoup.

    Voila mon programme:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    function varargout = Untitled100(varargin)
    % UNTITLED100 MATLAB code for Untitled100.fig
    %      UNTITLED100, by itself, creates a new UNTITLED100 or raises the existing
    %      singleton*.
    %
    %      H = UNTITLED100 returns the handle to a new UNTITLED100 or the handle to
    %      the existing singleton*.
    %
    %      UNTITLED100('CALLBACK',hObject,eventData,handles,...) calls the local
    %      function named CALLBACK in UNTITLED100.M with the given input arguments.
    %
    %      UNTITLED100('Property','Value',...) creates a new UNTITLED100 or raises the
    %      existing singleton*.  Starting from the left, property value pairs are
    %      applied to the GUI before Untitled100_OpeningFcn gets called.  An
    %      unrecognized property name or invalid value makes property application
    %      stop.  All inputs are passed to Untitled100_OpeningFcn via varargin.
    %
    %      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
    %      instance to run (singleton)".
    %
    % See also: GUIDE, GUIDATA, GUIHANDLES
    
    % Edit the above text to modify the response to help Untitled100
    
    % Last Modified by GUIDE v2.5 26-Jun-2011 10:42:02
    
    % Begin initialization code - DO NOT EDIT
    gui_Singleton = 1;
    gui_State = struct('gui_Name',       mfilename, ...
                       'gui_Singleton',  gui_Singleton, ...
                       'gui_OpeningFcn', @Untitled100_OpeningFcn, ...
                       'gui_OutputFcn',  @Untitled100_OutputFcn, ...
                       'gui_LayoutFcn',  [] , ...
                       'gui_Callback',   []);
    if nargin && ischar(varargin{1})
        gui_State.gui_Callback = str2func(varargin{1});
    end
    
    if nargout
        [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
    else
        gui_mainfcn(gui_State, varargin{:});
    end
    % End initialization code - DO NOT EDIT
    
    
    % --- Executes just before Untitled100 is made visible.
    function [TestData, Motor, Drive, Comments]=Untitled100_OpeningFcn(hObject, eventdata, handles, varargin)
    handles.output = hObject;
    [TestData, Motor, Drive, Comments] = read_BENG_MotorTestbench; 
    cla(handles.axes1,'reset')
    guidata(hObject, handles); %updates the handles
    set (handles.text3,'string', Motor.Name);
    set (handles.text4,'string', Motor.P_nom);
    set (handles.text5,'string', Motor.I_nom);
    set (handles.text6,'string', Motor.U_nom);
    set (handles.text8,'string', Motor.RPM_nom);
    set (handles.text7,'string', Motor.cos_phi);
    handles.timer = timer('TimerFcn',{@timcb handles}, ...
                            'Period', 1.0, ...
                            'ExecutionMode','fixedRate');
    start(handles.timer);
    iconeCNRS = imread('C:\Documents and Settings\olivier.calcoen\My Documents\MATLAB\MATLAB\images[1].jpg');
    axes(handles.axes4)
    image(iconeCNRS)
    axis off;
    set(hObject,'toolbar','figure')
    
    
    % --- Outputs from this function are returned to the command line.
    function varargout = Untitled100_OutputFcn(hObject, eventdata, handles)
    % varargout  cell array for returning output args (see VARARGOUT);
    
    % hObject    handle to figure
    % eventdata  reserved - to be defined in a future version of MATLAB
    % handles    structure with handles and user data (see GUIDATA)
    
    % Get default command line output from handles structure
    varargout{1} = handles.output;
    
    function timcb(hObject,eventdata,handles)
    
    set(handles.text9,'string',datestr(now,13))
    
    
    % --- Executes on button press in radiobutton3.
    function radiobutton3_Callback(hObject, eventdata, handles,TestData, Motor, Drive, Comments)
    h = findobj(gcbf, 'style', 'radio');
    set(h, 'value', 0);
    set(gcbo, 'value', 1);
    
    [TestData, Motor, Drive, Comments] = read_BENG_MotorTestbench; C'est donc ici le problème
    cla(handles.axes1,'reset')
      
    % reworking the data to plotable data formats + gridding
    % -------------------------------------------------------------------------
    
    Nmin = min(TestData.RPM);
    Nmax = max(TestData.RPM);
    Nsteps = Nmin:(Nmax-Nmin)/34:Nmax;
    
    Tmin = min(TestData.Torque);
    Tmax = max(TestData.Torque);
    
    Pnom = Motor.P_nom/1000; %[kW]
    Nnom = Motor.RPM_nom; %[rpm]
    Tnom = Pnom*1000/(Nnom*2*pi/60); %[Nm]
    P_mech = TestData.RPM.*TestData.Torque*2*pi/60;
    
    EffDrive = TestData.P_drive.P./TestData.P_in.P;
    EffMotor = P_mech./TestData.P_drive.P;
    EffTotal = P_mech./TestData.P_in.P;
    %Et_list = data; % [T,N,Eff]
    
    test = Tmax/30;
    
    [nGrid,tGrid]=meshgrid(Nsteps,(Tmin-test):test:(Tmax+test));
    % [Nmat,Tmat]=meshgrid(250:(Nmax-250)/100:Nmax,0:(Tmax-0)/100:Tmax);
    
    EffGridMotor = griddata(TestData.RPM, TestData.Torque, EffMotor ,nGrid,tGrid);
    EffGridDrive = griddata(TestData.RPM, TestData.Torque, EffDrive ,nGrid,tGrid);
    EffGridTotal = griddata(TestData.RPM, TestData.Torque, EffTotal ,nGrid,tGrid);
    
    %xlswrite(['xls_2D_maps\', fileName , '_motor.xls'], [[0;tGrid(:,1)],[nGrid(1,:); effGridMotor]]);
    %xlswrite(['xls_2D_maps\', fileName , '_drive.xls'], [[0;tGrid(:,1)],[nGrid(1,:); effGridDrive]]);
    %xlswrite(['xls_2D_maps\', fileName , '_total.xls'], [[0;tGrid(:,1)],[nGrid(1,:); effGrid]]);
    
    % Motor Lines
    % -------------------------------------------------------------------------
    
    torqueLine = zeros(2,10);
    torqueLine(1,:) = [0:(1-0)/9:1];
    torqueLine(2,:) = 1*ones(1,10);
    
    speedLine = zeros(2,10);
    speedLine(1,:) = 1*ones(1,10);
    speedLine(2,:) = [0:Tmax/9:Tmax];
    
    powerLine = zeros(2,50);
    powerLine(1,:) = [1:(Nmax-1)/49:Nmax];
    powerLine(2,:) = 1./powerLine(1,:);
    %figure
    %set(gca,'FontSize',18)
    %hold on
    %mesh(nGrid,tGrid,EffGridTotal)
    %plot3(TestData.RPM, TestData.Torque, EffTotal,'o')
    %title('Total efficiency [%]')
    %xlabel('Speed [rpm]')
    %ylabel('Torque [Nm]')
    %figure('Name','Total Efficiency Map') 
    
    T=Pnom./(2*pi*Nsteps/60);
    n = 1;
    for i=Nnom:Nmax
    T(n)=Pnom*1000/(2*pi*i/60);
    n = n +1;
    end
    N=Nmin:Nnom;
    axes(handles.axes1)
    hold on
    
    [C,h] = contourf(nGrid,tGrid,EffGridTotal,[10 20 30 40 50 55 60 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]/100);
    text_handle = clabel(C,h);
    
    plot(torqueLine(1,:),torqueLine(2,:),'LineStyle','-','Color','white','LineWidth',2)
    plot(speedLine(1,:),speedLine(2,:),'LineStyle','-','Color','white','LineWidth',2)
    plot(powerLine(1,:),powerLine(2,:),'LineStyle','-','Color','white','LineWidth',2)
    plot(N,Tnom,'--bs','LineWidth',2)
    plot(Nnom:Nmax,T,'--bs','LineWidth',2)
    title('Total efficiency [%]')
    xlabel('N [rpm]')
    ylabel('T [Nm]')
    guidata(hObject, handles); %updates the handles
    set(hObject);
    colorbar('FontSize',10)

    De plus, le début du programme à charger est celui-ci:


    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    function [ TestData, Motor, Drive, Comments ] = read_BENG_MotorTestbench
     
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %% Initialise Data
     
    % Initialise the matrices
    TestData.DateTime = [];
    TestData.TempMotor = [];
    TestData.TempAmb = [];
    TestData.RPM = [];
    TestData.Torque = [];
    TestData.P_in.CH1.P = [];
    TestData.P_in.CH1.U = [];
    TestData.P_in.CH1.I = [];
    TestData.P_in.CH1.PF = [];
    TestData.P_in.CH2.P = [];
    TestData.P_in.CH2.U = [];
    TestData.P_in.CH2.I = [];
    TestData.P_in.CH2.PF = [];
    TestData.P_in.CH3.P = [];
    TestData.P_in.CH3.U = [];
    TestData.P_in.CH3.I = [];
    TestData.P_in.CH3.PF = [];
    TestData.P_drive.CH1.P = [];
    TestData.P_drive.CH1.U = [];
    TestData.P_drive.CH1.I = [];
    TestData.P_drive.CH1.PF = [];
    TestData.P_drive.CH2.P = [];
    TestData.P_drive.CH2.U = [];
    TestData.P_drive.CH2.I = [];
    TestData.P_drive.CH2.PF = [];
    TestData.P_drive.CH3.P = [];
    TestData.P_drive.CH3.U = [];
    TestData.P_drive.CH3.I = [];
    TestData.P_drive.CH3.PF = [];
    TestData.P_in.P = [];
    TestData.P_in.U = [];
    TestData.P_in.I = [];
    TestData.P_in.PF = [];
    TestData.P_drive.P = [];
    TestData.P_drive.U = [];
    TestData.P_drive.I = [];
    TestData.P_drive.PF = [];
     
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %% Read File
     
    % Ask user to select files
    [FileName,PathName,FilterIndex] = uigetfile({'.txt'},'Select BENG Motor Testbench Log Files', 'MultiSelect', 'on');

    Comment je peux récupérer le 'FileName,PathName et FilterIndex'?
    Merci

  2. #2
    Invité
    Invité(e)
    Par défaut
    Bonjour,

    Dans un premier temps:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    radiobutton3_Callback(hObject, eventdata, handles,TestData, Motor, Drive, Comments)
    Etant sous GUIDE, tu ne pourras pas les faire passer comme ceci.
    L'utilisation habituelle pour faire passer les variables entre les différentes fonctions est de les stocker dans la structure handles comme ceci:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    function [TestData, Motor, Drive, Comments]=Untitled100_OpeningFcn(hObject, eventdata, handles, varargin)
    
    [handles.TestData, handles.Motor, handles.Drive, handles.Comments] = read_BENG_MotorTestbench;
    guidata(hObject,handles) % ici dans l'OpeningFcn
    % guidata(gcbf,handles) % dans les autres Callback
    Puis
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    function radiobutton3_Callback(hObject, eventdata, handles)
    h = findobj(gcbf, 'style', 'radio');
    set(h, 'value', 0);
    set(hObject, 'value', 1); % plus correct
    
    cla(handles.axes1,'reset')
      
    % reworking the data to plotable data formats + gridding
    % -------------------------------------------------------------------------
    
    Nmin = min(handles.TestData.RPM);
    Nmax = max(handles.TestData.RPM);
    ...

  3. #3
    Membre confirmé
    Homme Profil pro
    Étudiant
    Inscrit en
    Juin 2011
    Messages
    46
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Nord (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Étudiant
    Secteur : Industrie

    Informations forums :
    Inscription : Juin 2011
    Messages : 46
    Par défaut
    Merci beaucoup,

    cela marche très bien.
    Cela va m'être très utile !!!

    merci !!!

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Réponses: 24
    Dernier message: 25/09/2007, 11h53
  2. Réponses: 3
    Dernier message: 21/06/2007, 01h10
  3. Réponses: 3
    Dernier message: 14/03/2007, 15h30
  4. Récupérer les données d'un fichier image
    Par Jim_Nastiq dans le forum Bibliothèques
    Réponses: 12
    Dernier message: 24/01/2007, 14h22
  5. [](VB) Récupérer les données dans un fichier .xml
    Par Furius dans le forum VBScript
    Réponses: 4
    Dernier message: 02/10/2005, 20h39

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo