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 :

erreur Attempt to reference field of non-structure array.


Sujet :

MATLAB

  1. #1
    Membre régulier
    Profil pro
    Doctorant
    Inscrit en
    Février 2011
    Messages
    258
    Détails du profil
    Informations personnelles :
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Doctorant
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Février 2011
    Messages : 258
    Points : 88
    Points
    88
    Par défaut erreur Attempt to reference field of non-structure array.
    bonjour ;

    j'ai trouvé cet exemple de code qui apparemment marche:
    La fonction
    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
     
    function [] = svm_3d_matlab_vis(svmStruct,Xdata,group)
    sv =  svmStruct.SupportVectors;
    alphaHat = svmStruct.Alpha;
    bias = svmStruct.Bias;
    kfun = svmStruct.KernelFunction;
    kfunargs = svmStruct.KernelFunctionArgs;
    sh = svmStruct.ScaleData.shift; % shift vector
    scalef = svmStruct.ScaleData.scaleFactor; % scale vector
     
    group = group(~any(isnan(Xdata),2));
    Xdata =Xdata(~any(isnan(Xdata),2),:); % remove rows with NaN 
     
    % scale and shift data
    Xdata1 = repmat(scalef,size(Xdata,1),1).*(Xdata+repmat(sh,size(Xdata,1),1));
    k = 50; 
    cubeXMin = min(Xdata1(:,1));
    cubeYMin = min(Xdata1(:,2));
    cubeZMin = min(Xdata1(:,3));
     
    cubeXMax = max(Xdata1(:,1));
    cubeYMax = max(Xdata1(:,2));
    cubeZMax = max(Xdata1(:,3));
    stepx = (cubeXMax-cubeXMin)/(k-1);
    stepy = (cubeYMax-cubeYMin)/(k-1);
    stepz = (cubeZMax-cubeZMin)/(k-1);
    [x, y, z] = meshgrid(cubeXMin:stepx:cubeXMax,cubeYMin:stepy:cubeYMax,cubeZMin:stepz:cubeZMax);
    mm = size(x);
    x = x(:);
    y = y(:);
    z = z(:);
    f = (feval(kfun,sv,[x y z],kfunargs{:})'*alphaHat(:)) + bias;
    t = strcmp(group, group{1});
     
    % unscale and unshift data 
    Xdata1 =(Xdata1./repmat(scalef,size(Xdata,1),1)) - repmat(sh,size(Xdata,1),1);
    x =(x./repmat(scalef(1),size(x,1),1)) - repmat(sh(1),size(x,1),1);
    y =(y./repmat(scalef(2),size(y,1),1)) - repmat(sh(2),size(y,1),1);
    z =(z./repmat(scalef(3),size(z,1),1)) - repmat(sh(3),size(z,1),1);
    figure
    plot3(Xdata1(t, 1), Xdata1(t, 2), Xdata1(t, 3), 'b.');
    hold on
    plot3(Xdata1(~t, 1), Xdata1(~t, 2), Xdata1(~t, 3), 'r.');
    hold on
    % load unscaled support vectors for plotting
    sv = svmStruct.SupportVectorIndices;
    sv = [Xdata1(sv, :)];
    plot3(sv(:, 1), sv(:, 2), sv(:, 3), 'go');
    legend(group{1},group{end},'support vectors')
     
    x0 = reshape(x, mm);
    y0 = reshape(y, mm);
    z0 = reshape(z, mm);
    v0 = reshape(f, mm);
     
    [faces,verts,colors] = isosurface(x0, y0, z0, v0, 0, x0);
    patch('Vertices', verts, 'Faces', faces, 'FaceColor','k','edgecolor', 'none', 'FaceAlpha', 0.5);
    grid on
    box on
    view(3)
    hold off
    end


    mais dés que j'essaie de le compiler moi j'ai cette erreur
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    Attempt to reference field of non-structure array.
     
    Error in svm_3d_matlab_vis (line 2)
    sv =  svmStruct.SupportVectors;

  2. #2
    Membre habitué
    Homme Profil pro
    Ingénieur en science de l'environnement
    Inscrit en
    Août 2013
    Messages
    97
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Suisse

    Informations professionnelles :
    Activité : Ingénieur en science de l'environnement

    Informations forums :
    Inscription : Août 2013
    Messages : 97
    Points : 149
    Points
    149
    Par défaut

    mais dés que j'essaie de le compiler moi j'ai cette erreur
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    Attempt to reference field of non-structure array.
     
    Error in svm_3d_matlab_vis (line 2)
    sv =  svmStruct.SupportVectors;
    La réponse est dans la question.

    Tu essaies d'accéder à svmStruct.SupportVectors alors qu'apparement svmStruct n'est pas une structure.

    que donne

    ?

Discussions similaires

  1. Attempt to reference field of non-structure array
    Par condrillon89 dans le forum Interfaces Graphiques
    Réponses: 10
    Dernier message: 21/05/2011, 18h25
  2. [Débutant] Attempt to reference field of non-structure array.
    Par ptichum dans le forum Interfaces Graphiques
    Réponses: 4
    Dernier message: 06/01/2010, 22h20
  3. Attempt to reference field of non-structure array.
    Par gmachi10 dans le forum Interfaces Graphiques
    Réponses: 2
    Dernier message: 26/06/2009, 09h01
  4. erreur :Cell contents assignment to a non-cell array object.
    Par lince102 dans le forum Interfaces Graphiques
    Réponses: 5
    Dernier message: 17/12/2007, 15h09
  5. Réponses: 5
    Dernier message: 20/10/2006, 14h31

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