WICHTIG: Der Betrieb von goMatlab.de wird privat finanziert fortgesetzt. - Mehr Infos...

Mein MATLAB Forum - goMatlab.de

Mein MATLAB Forum

 
Gast > Registrieren       Autologin?   

Partner:




Forum
      Option
[Erweitert]
  • Diese Seite per Mail weiterempfehlen
     


Gehe zu:  
Neues Thema eröffnen Neue Antwort erstellen

Variable aus Unterprogramm in Workspace speichern

 

armerTropf

Gast


Beiträge: ---
Anmeldedatum: ---
Wohnort: ---
Version: ---
     Beitrag Verfasst am: 05.02.2019, 21:27     Titel: Variable aus Unterprogramm in Workspace speichern
  Antworten mit Zitat      
Hallo liebe Matlab-Gemeinde,

ich habe ein großes Problem. Und zwar nutze ich die externe Matlab-Funktion "iso2mesh" (http://iso2mesh.sourceforge.net/cgi-bin/index.cgi?metch/README). Ich nutze diese, um zwischen zwei Volumen die Schnittpunkte zu berechnen. Innerhalb der Funktion "linextriangle" bekomme ich immer wieder die Fehlermeldung "degenerated line". Da ich jedoch über 250000 Punkte zur Berechnung habe, würde ich gerne rausfinden lassen, welche Punkte dem Programm nicht gefallen. Dies ist mir bisher jedoch nicht möglich, da das verwendete Programm erst durch eine Unterprogramme aufgerufen wird und die Daten nur bei erfolgreichem Durchrechnen abspeichert. Ich habe auch schon die Deklaration als globale Variable oder über assignin versucht, aber bisher hat nix funktionert... Kann mir vielleicht jemand weiterhelfen?

Die verwendete Struktur sieht wie folgt aus:
Code:

function [Int_Point, Int_Face, Int_weights]=proj2mesh(Points_large,ConnectivityList_large,Points_small,vertex_normals_small,NeighborPairs)

            [Int_Point, Int_Face, Int_weights]=proj2mesh_parallelized(Points_large,ConnectivityList_large,Points_small,vertex_normals_small,NeighborPairs);%,direction_projection);

        end

function [newpt elemid weight]=proj2mesh(v,f,pt,nv,cn,nv_small_paired)
%  [newpt elemid weight]=proj2mesh(v,f,pt,nv,cn)
%
%  project a point cloud on to the surface mesh (surface can only be triangular)
%
%  author: Qianqian Fang <fangq at nmr.mgh.harvard.edu>
%  date: 12/12/2008
%
% parameters:
%      v: node coordinate of the surface mesh (nn x 3)
%      f: element list of the surface mesh (3 columns for
%            triangular mesh, 4 columns for cubic surface mesh)
%      pt: points to be projected, 3 columns for x,y and z respectively
%      nv: nodal norms (vector) calculated from nodesurfnorm.m
%          with dimensions of (size(v,1),3)
%      cn: a integer vector with the length of p, denoting the closest
%          surface nodes (indices of v) for each point in p. this
%          value can be calculated from dist2surf.m
%
%      if nv and cn are not supplied, proj2mesh will project the point
%      cloud onto the surface by the direction pointing to the centroid
%      of the mesh
%
% outputs:
%      newpt: the projected points from p
%      elemid: a vector of length of p, denotes which surface trangle (in elem)
%             contains the projected point
%      weight: the barycentric coordinate for each projected points, these are
%             the weights
%
% Please find more information at http://iso2mesh.sf.net/cgi-bin/index.cgi?metch
%
% this function is part of "metch" toobox, see COPYING for license

cent=mean(v);
enum=length(f);
ec=reshape(v(f(:,1:3)',:)', [3 3,enum]);
centroid=squeeze(mean(ec,2));
newpt =zeros(size(pt,1),3);
elemid=zeros(size(pt,1),1);
weight=zeros(size(pt,1),3);

if(nargin==5)
       % if nv and cn are supplied, use nodal norms to project the points
       direction=nv(cn,:);
% % elseif(nargin==6)
% %         % if vector from small shape is supplied, use this for direction of
% %         % projection
% %        direction = nv_small_paired;
elseif(nargin==3)
       % otherwise, project toward the centroid
       direction=pt-repmat(cent,size(pt,1),1);
end

parfor t=1:size(pt,1)
% for t=1:size(pt,1)  
    % calculate the distance to the centroid
    dist2=repmat(pt(t,:)',1,enum)-centroid;
    maxdist2=sum((pt(t,:)-cent).*(pt(t,:)-cent));
    c0=sum(dist2.*dist2);

    % only search for the elements that are enclosed by a sphere centered at
    % pt(t,Smile passing by the centroid, this may failed under some extreme conditions,
    % which I ignored here
    idx=find(c0<maxdist2);

    % sort the distances to accelate the calculation
    [c1,sorted]=sort(c0(idx));

    for i=1:length(idx)
   
        % project the point along vector direction and calculate the intersection to a plane
%    i
%     t
        [inside,p,w]=linextriangle(pt(t,:), pt(t,:)+direction(t,:),v(f(idx(sorted(i)),:),:));
   
   % the intersection is within the current trianglar surface
        if(inside)
            newpt(t,:)=p;
            weight(t,:)=w;
            elemid(t)=idx(sorted(i));
            break;
        end
    end
end

function [isinside,pt,coord]=linextriangle(p0,p1,plane)
%  [isinside,pt,coord]=linextriangle(p0,p1,plane)
%
%  calculate the intersection of a 3d line (passing two points)
%  with a plane (determined by 3 points)
%
%  author: Qianqian Fang <fangq at nmr.mgh.harvard.edu>
%  date: 12/12/2008
%
% parameters:
%      p0: a 3d point in form of (x,y,z)
%      p1: another 3d point in form of (x,y,z), p0 and p1 determins the line
%      plane: a 3x3 matrix, each row is a 3d point in form of (x,y,z)
%             this is used to define a plane
% outputs:
%      isinside: a boolean variable, 1 for the intersection is within the
%               3d triangle determined by the 3 points in plane; 0 is outside
%      pt: the coordinates of the intersection point
%      coord: 1x3 vector, if isinside=1, coord will record the barycentric
%          coordinate for the intersection point within the triangle;
%          otherwise it will be all zeros.
%
% for degenerated lines or triangles, this will stop
%
% Please find more information at http://iso2mesh.sf.net/cgi-bin/index.cgi?metch
%
% this function is part of "metch" toobox, see COPYING for license

[a,b,c,d]=getplanefrom3pt(plane);
     
if(a*a+b*b+c*c==0.0)
%         k = find(a*a+b*b+c*c==0.0);
        disp(num2str(k));
        error('degenerated plane');
end

dl_n=sum([a b c].*(p1-p0));
% n = size(dl_n);

if(dl_n==0.0)
%         k = find(dl_n==0.0);
%         disp(num2str(k));
%         disp(num2str(n));
        error('degenerated line');
end

% solve for the intersection point
t=-(a*p0(1)+b*p0(2)+c*p0(3)+d)/dl_n;
pt=p0+(p1-p0)*t;


dist=sum(abs(diff(plane)));
[md,imax]=sort(dist);
if(md(2)==0.0)
        error('degenerated triangle');
end
goodidx=imax(2:end);

ptproj=pt(goodidx);
mat0=[plane(:,goodidx)',ptproj';1 1 1 1];

isinside=0;
coord=[0 0 0];

det1=det(mat0(:,[4 2 3],:));
det2=det(mat0(:,[1 4 3],:));
if(det1*det2<0)
        return;
end
det3=det(mat0(:,[1 2 4],:));
if(det2*det3<0)
        return;
end
if(det1*det3<0)
        return;
end
isinside=1;
det0=det(mat0(:,1:3));

coord=[det1 det2 det3]/det0;

 

Mich würden dabei besonders die Variabeln a,b,c,d, p1 und p0 interessieren.

Schon vorab vielen, vielen Dank für jede Hilfe!

Liebe Grüße

Euer armerTropf


Harald
Forum-Meister

Forum-Meister


Beiträge: 24.448
Anmeldedatum: 26.03.09
Wohnort: Nähe München
Version: ab 2017b
     Beitrag Verfasst am: 05.02.2019, 21:43     Titel:
  Antworten mit Zitat      
Hallo,

du kannst z.B. vor dem error-Befehl mit save die gewünschten Variablen in eine .mat-Datei schreiben und dort abspeichern. Oder du setzt einen Haltepunkt in die error-Zeile.

Grüße,
Harald
_________________

1.) Ask MATLAB Documentation
2.) Search gomatlab.de, google.de or MATLAB Answers
3.) Ask Technical Support of MathWorks
4.) Go mad, your problem is unsolvable ;)
Private Nachricht senden Benutzer-Profile anzeigen
 
armerTropf

Gast


Beiträge: ---
Anmeldedatum: ---
Wohnort: ---
Version: ---
     Beitrag Verfasst am: 05.02.2019, 22:20     Titel:
  Antworten mit Zitat      
Hallo Harald,

vielen Dank für Deine schnelle Hilfe!
Da hätte ich ja echt auch selber draufkommen können... Es scheint zu funktionieren! Besten Dank!!!

Liebe Grüße

armerTropf
 
Neues Thema eröffnen Neue Antwort erstellen



Einstellungen und Berechtigungen
Beiträge der letzten Zeit anzeigen:

Du kannst Beiträge in dieses Forum schreiben.
Du kannst auf Beiträge in diesem Forum antworten.
Du kannst deine Beiträge in diesem Forum nicht bearbeiten.
Du kannst deine Beiträge in diesem Forum nicht löschen.
Du kannst an Umfragen in diesem Forum nicht mitmachen.
Du kannst Dateien in diesem Forum posten
Du kannst Dateien in diesem Forum herunterladen
.





 Impressum  | Nutzungsbedingungen  | Datenschutz | FAQ | goMatlab RSS Button RSS

Hosted by:


Copyright © 2007 - 2024 goMatlab.de | Dies ist keine offizielle Website der Firma The Mathworks

MATLAB, Simulink, Stateflow, Handle Graphics, Real-Time Workshop, SimBiology, SimHydraulics, SimEvents, and xPC TargetBox are registered trademarks and The MathWorks, the L-shaped membrane logo, and Embedded MATLAB are trademarks of The MathWorks, Inc.