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

Handles in Subplot überlagern sich immer

 

mat_macs
Forum-Anfänger

Forum-Anfänger


Beiträge: 26
Anmeldedatum: 27.09.10
Wohnort: ---
Version: ---
     Beitrag Verfasst am: 27.04.2012, 15:25     Titel: Handles in Subplot überlagern sich immer
  Antworten mit Zitat      
Hallo zusammen,

ich bin ein ziemlicher Matlabfrischling und hänge jetzt schon ewig an dem Problem, dass sich die Handles in meinem Suplot überlagern, zumindest die Y-Labels des rechten Bildes mit dem Diagramm in der Mitte.
Ich habe schon einiges probiert, aber nur die Schriftgröße ändern hat wirklich Erfolg gebracht. Allerdings kann das ja nicht die einzige Lösung sein.

Ich habe noch zwei Ansätze, komme mit beiden aber nicht zurecht:
1) Outer and inner position
2) kill_siblings

Zu 1):
Code:

% compute outerposition and insets relative to figure bounds
            rw = max(row)-min(row)+1;
            cw = max(col)-min(col)+1;
            width = def_pos(3)/(ncols - inset(1) - inset(3));
            height = def_pos(4)/(nrows - inset(2) - inset(4));
            inset = inset.*[width height width height];
            outerpos = [def_pos(1) + min(col)*width - inset(1), ...
                def_pos(2) + min(row)*height - inset(2), ...
                width*cw height*rw];

            % adjust outerpos and insets for axes around the outside edges
            if min(col) == 0
                inset(1) = def_pos(1);
                outerpos(3) = outerpos(1)+outerpos(3);
                outerpos(1) = 0;
            end
            if min(row) == 0,
                inset(2) = def_pos(2);
                outerpos(4) = outerpos(2)+outerpos(4);
                outerpos(2) = 0;
            end
            if max(col) == ncols-1,
                inset(3) = max(0,1-def_pos(1)-def_pos(3));
                outerpos(3) = 1-outerpos(1);
            end
            if max(row) == nrows-1,
                inset(4) = max(0,1-def_pos(2)-def_pos(4));
                outerpos(4) = 1-outerpos(2);
            end

            % compute inner position
            position = [outerpos(1:2) + inset(1:2),...
                outerpos(3:4) - inset(1:2) - inset(3:4)];


Das ist der Code aus dem Subplot.m --> ich weiß nicht, ob ich dort ändern muss, damit die Subplots inklusive ihrer Legende bzw. Achsenbeschriftung eine feste Größe haben und sich nicht mehr überlagern.

Zu 2)
Ich habe den Befehl "kill_siblings" gefunden, welcher übereinander positionierte Plots, welche mit 'Position' generiert wurden, löscht und den aktuelleren darüber legt.
Aber ich will ja nicht, dass meine Plots gelöscht werden, sondern einfach nur, dass ich die Subplots sich egal welche Schriftgröße ich wähle, oder ich die Labels dünn, dick, demi oder wie auch immer mache, nicht überlagern.

Könnt ihr mir diesbezüglich helfen? Ich komme echt nicht ohne Hilfe weiter.

Vielen Dank im Voraus!
Viele Grüße,
Max

BildFFTvsTime.png
 Beschreibung:

Download
 Dateiname:  BildFFTvsTime.png
 Dateigröße:  3.13 MB
 Heruntergeladen:  1021 mal
Private Nachricht senden Benutzer-Profile anzeigen


Harald
Forum-Meister

Forum-Meister


Beiträge: 24.501
Anmeldedatum: 26.03.09
Wohnort: Nähe München
Version: ab 2017b
     Beitrag Verfasst am: 27.04.2012, 15:41     Titel:
  Antworten mit Zitat      
Hallo,

du meinst wohl Labels, nicht Handles?

Da ist es vielleicht geschickter, die Koordinatensysteme direkt selbst mit AXES zu positionieren.

Code:
ax = axes('position', [left lower width height])


Grüße,
Harald
Private Nachricht senden Benutzer-Profile anzeigen
 
mat_macs
Themenstarter

Forum-Anfänger

Forum-Anfänger


Beiträge: 26
Anmeldedatum: 27.09.10
Wohnort: ---
Version: ---
     Beitrag Verfasst am: 27.04.2012, 15:53     Titel:
  Antworten mit Zitat      
Hallo Harald,
also ich habe bei den LABELS bisher die Schriftgröße, Schriftart und Eigenschaften wie dünn, kursiv, fett etc. probiert.
Als HANDLES habe ich die eigentliche Grafik, also das 3dimensionale Diagramm bezeichnet, da ich dachte, dass das als Handle bezeichnet wird. Ein Handle ist ja eine Oberklasse von allenmöglichen anderen Klassenobjekten, wobei ich das auch nicht so ganz verstehe.
Also um nochmal genau das Problem zu beschreiben - das Ylabel "Frequenz in Hz" der rechten Grafik steht immer in die Diagrammfläche in der Mitte hinein und ich möchte, dass jede Diagrammfläche samt X-u. YLabel als ein Objekt sozusagen betrachtet wird, wobei die Objekte sich nicht schneiden oder überlagern dürfen.

Zu deinem Code: Diese Art der Definition habe ich auch schon in der Hilfe gelesen, allerdings ist 'Position' in den mir zur Verfügung stehenden Dateien anders definiert.

Im eigentlichen Programm, was die FFTvsTime berechnet, wie folgt:
Code:

%% plot settings
SHOW_MAGNITUDES = 1;
FIGURE_SIZE = [1280,800];

clear pset;
pset.FontSize = 10;
pset.LineWidth = 1.5;
pset.Box = 'on';
pset.Title.String = '';
pset.Title.FontSize = 10;
pset.Title.FontWeight = 'bold';
pset.colorbar.FontSize = 14;
pset.colorbar.Xlabel.FontWeight = 'demi';
pset.colorbar.Xlabel.FontSize = 12;
pset.colorbar.Xlabel.String = {'Beschleunigungs-';'pegel in dB'}; %für Beschleunigungsaufnehmer
%pset.colorbar.Xlabel.String = {'Schalldruck-};{pegel in dB'};    %für Mikrofonaufnahmen
pset.Xlabel.FontWeight = 'demi';
pset.Ylabel.FontWeight = pset.Xlabel.FontWeight;
pset.Xlabel.FontSize = 16;
pset.Ylabel.FontSize = pset.Xlabel.FontSize;
pset.Xlabel.String = 'Zeit in s';
pset.Ylabel.String = 'Frequenz in Hz';
pset.YScale = 'log';
pset.Position.width = 0.21;
% pset.YTick = [8 60 160];
% pset.YTickLabel = {'8','60','160'};
 


und dann im dazugehörigen m-file, welches die Plot_settings bestimmt so:
Code:

case 'Position'
                    curPos = get(hParent,'Position');
                    posPropList = fieldnames(subStruct.(propertyList{propIdx}));
                    for posValIdx = 1:length(posPropList)
                        switch posPropList{posValIdx}
                            case 'x'
                                posIdx = 1;
                            case 'y'
                                posIdx = 2;
                            case 'width'
                                posIdx = 3;
                            case 'height'
                                posIdx = 4;
                            otherwise
                                error(['Unknown field in Position: ' ...
                                    char(posPropList(posValIdx))]);
                        end
                        newPos = curPos;
                        newPos(posIdx) = subStruct.(propertyList{propIdx}).(posPropList{posValIdx});
                        set(hParent,'Position',newPos);
                    end
 



Damit kann ich halt aber nichts anfangen. Ich verstehe auch nicht, wo ich in diesen Code deinen Lösungsvorschlag implementieren kann.

Viele Grüße,
Max
Private Nachricht senden Benutzer-Profile anzeigen
 
Harald
Forum-Meister

Forum-Meister


Beiträge: 24.501
Anmeldedatum: 26.03.09
Wohnort: Nähe München
Version: ab 2017b
     Beitrag Verfasst am: 27.04.2012, 16:13     Titel:
  Antworten mit Zitat      
Hallo,

was ist denn der Code, den du letztlich ausführst?

Mir scheint, dass der Code (erster Beitrag und zweiter Teil des zweiten Beitrags) hier Kopien aus Befehlen sind? Zudem frage ich mich, wer sich den verbleibenden Code ausgedacht hat und was er sich dabei gedacht hat. Für sich genommen sehe ich da jedenfalls recht wenig Sinn dahinter.

Grüße,
Harald
Private Nachricht senden Benutzer-Profile anzeigen
 
mat_macs
Themenstarter

Forum-Anfänger

Forum-Anfänger


Beiträge: 26
Anmeldedatum: 27.09.10
Wohnort: ---
Version: ---
     Beitrag Verfasst am: 27.04.2012, 17:07     Titel:
  Antworten mit Zitat      
Hi,

Harald, die PN die ich geschickt habe, verliert jetzt ihre Gültigkeit, denn ich denke ich bin der Lösung sehr nahe,
es wird höchstwahrscheinlich an meinem Subplot.m-File liegen.
Meine Frage lautet nun, wo definiere ich in meinem Subplot die OuterPosition als ActivePositionProperty? Die Hilfedatei AutomaticAxis Resize :: AxesProperties hat mich auf die Idee gebracht, aber ich kann es leider noch nicht umsetzen.

Hier mein Subplot:
Code:


function theAxis = subplot(nrows, ncols, thisPlot, varargin)
%SUBPLOT Create axes in tiled positions.
%   H = SUBPLOT(m,n,p), or SUBPLOT(mnp), breaks the Figure window
%   into an m-by-n matrix of small axes, selects the p-th axes for
%   the current plot, and returns the axis handle.  The axes are
%   counted along the top row of the Figure window, then the second
%   row, etc.  For example,
%
%       SUBPLOT(2,1,1), PLOT(income)
%       SUBPLOT(2,1,2), PLOT(outgo)
%
%   plots income on the top half of the window and outgo on the
%   bottom half. If the CurrentAxes is nested in a uipanel the
%   panel is used as the parent for the subplot instead of the
%   current figure.
%
%   SUBPLOT(m,n,p), if the axis already exists, makes it current.
%   SUBPLOT(m,n,p,'replace'), if the axis already exists, deletes it and
%   creates a new axis.
%   SUBPLOT(m,n,p,'align') places the axes so that the plot boxes
%   are aligned, but does not prevent the labels and ticks from
%   overlapping.
%   SUBPLOT(m,n,P), where P is a vector, specifies an axes position
%   that covers all the subplot positions listed in P.
%   SUBPLOT(H), where H is an axis handle, is another way of making
%   an axis current for subsequent plotting commands.
%
%   SUBPLOT('position',[left bottom width height]) creates an
%   axis at the specified position in normalized coordinates (in
%   in the range from 0.0 to 1.0).
%
%   SUBPLOT(..., PROP1, VALUE1, PROP2, VALUE2, ...) sets the
%   specified property-value pairs on the subplot axis. To add the
%   subplot to a specific figure pass the figure handle as the
%   value for the 'Parent' property.
%
%   If a SUBPLOT specification causes a new axis to overlap an
%   existing axis, the existing axis is deleted - unless the position
%   of the new and existing axis are identical.  For example,
%   the statement SUBPLOT(1,2,1) deletes all existing axes overlapping
%   the left side of the Figure window and creates a new axis on that
%   side - unless there is an axes there with a position that exactly
%   matches the position of the new axes (and 'replace' was not specified),
%   in which case all other overlapping axes will be deleted and the
%   matching axes will become the current axes.
%
%   SUBPLOT(111) is an exception to the rules above, and is not
%   identical in behavior to SUBPLOT(1,1,1).  For reasons of backwards
%   compatibility, it is a special case of subplot which does not
%   immediately create an axes, but instead sets up the figure so that
%   the next graphics command executes CLF RESET in the figure
%   (deleting all children of the figure), and creates a new axes in
%   the default position.  This syntax does not return a handle, so it
%   is an error to specify a return argument.  The delayed CLF RESET
%   is accomplished by setting the figure's NextPlot to 'replace'.
%
%   Be aware when creating subplots from scripts that the Position
%   property of subplots is not finalized until either a drawnow
%   command is issued, or MATLAB returns to await a user command.
%   That is, the value obtained for subplot i by the command
%   get(h(i),'Position') will not be correct until the script
%   refreshes the plot or exits.
%
%   See also  GCA, GCF, AXES, FIGURE, UIPANEL

%   SUBPLOT(m,n,p,H) when H is an axes will move H to the specified
%   position.
%   SUBPLOT(m,n,p,H,PROP1,VALUE1,...) will move H and apply the
%   specified property-value pairs
%  
%   SUBPLOT(m,n,p) for non-integer p places the subplot at the
%   fraction p-floor(p) between the positions floor(p) and ceil(p)

%   Copyright 1984-2008 The MathWorks, Inc.
%   $Revision: 5.22.4.28 $  $Date: 2008/12/04 22:40:20 $

narg = nargin;

% First we check whether Handle Graphics uses MATLAB classes
isHGUsingMATLABClasses = feature('HGUsingMATLABClasses');

% Next we check whether we should ignore a possible v6 argument.
if isHGUsingMATLABClasses && narg >= 4 && ~ischar(nrows)
    arg = varargin{1};
    if ischar(arg) && strcmpi(arg,'v6')
        warning(['MATLAB:', mfilename, ':IgnoringV6Argument'],...
            ['Ignoring the ''v6'' argument to %s.',...
            '  This will become an error in a future release.'], upper(mfilename));
        narg = narg - 1;
        varargin(1) = [];
    end
end

% we will kill all overlapping axes siblings if we encounter the mnp
% or m,n,p specifier (excluding '111').
% But if we get the 'position' or H specifier, we won't check for and
% delete overlapping siblings:
kill_siblings = 0;
create_axis = true;
move_axis = false;
delay_destroy = false;
useAutoLayout = true;
tol = sqrt(eps);
parent = get(0,'CurrentFigure');
parentfigure = parent;
if ~isempty(parent) && ~isempty(get(parent,'CurrentAxes'))
    parent = get(get(parent,'CurrentAxes'),'Parent');
    parentfigure = parent;
    if ~strcmp(get(parentfigure,'Type'),'figure')
        parentfigure = ancestor(parent,'figure');
    end
end
pvpairs = {};
preventMove = false;
% This is the percent offset from the subplot grid of the plotbox.
inset = [.1 .18 .04 .1]; % [left bottom right top]

if narg == 0 % make compatible with 3.5, i.e. subplot == subplot(111)
    nrows = 111;
    narg = 1;
end

%check for encoded format
handle = '';
position = '';
explicitParent = false;
explicitPosition = false;

if narg == 1
    % The argument could be one of 3 things:
    % 1) a 3-digit number 100 < num < 1000, of the format mnp
    % 2) a 3-character string containing a number as above
    % 3) an axis handle
    code = nrows;

    % turn string into a number:
    if(ischar(code))
        code = str2double(code);
    end
   
    % Check for NaN and Inf.
    if (~isfinite(code))
        error(id('SubplotIndexNonFinite'),'Index must be a finite 3-digit number of the format mnp.')
    end

    % number with a fractional part can only be an identifier:
    if(rem(code,1) > 0)
        handle = code;
        if ~strcmp(get(handle,'type'),'axes')
            error(id('InvalidAxesHandle'),'Requires valid axes handle for input.')
        end
        create_axis = false;
        % all other numbers will be converted to mnp format:
    else
        % Check for input out of range
        if (code <= 100 || code >= 1000)
            error(id('SubplotIndexOutOfRange'),'Index must be a 3-digit number of the format mnp.')
        end
       
        thisPlot = rem(code, 10);
        ncols = rem( fix(code-thisPlot)/10,10);
        nrows = fix(code/100);
        if nrows*ncols < thisPlot
            error(id('SubplotIndexTooLarge'),'Index exceeds number of subplots.');
        end
        kill_siblings = 1;
        if(code == 111)
            create_axis   = false;
            delay_destroy = true;
        else
            create_axis   = true;
            delay_destroy = false;
        end
    end

elseif narg == 2
    % The arguments MUST be the string 'position' and a 4-element vector:
    if(strcmpi(nrows, 'position'))
        pos_size = size(ncols);
        if(pos_size(1) * pos_size(2) == 4)
            position = ncols;
            explicitPosition = true;
        else
            error(id('InvalidPositionParameter'),...
                'Position must be of the form [left bottom width height].')
        end
    else
        error(id('UnknownOption'),'Unknown command option.')
    end
    kill_siblings = 1; % Kill overlaps here also.
    useAutoLayout = true;%hier habe ich von false auf true geändert

elseif narg == 3
    % passed in subplot(m,n,p) -- we should kill overlaps
    % here too:
    kill_siblings = 1;

elseif narg >= 4
    if ~ischar(nrows)
        arg = varargin{1};
        if ~ischar(arg)
            % passed in subplot(m,n,p,H,...)
            handle = arg;
            parent = get(handle,'Parent');
            parentfigure = ancestor(handle,'figure');
            % If the parent is passed in explicitly, don't create a new figure
            % when the "NextPlot" property is set to "new" in the figure.
            explicitParent = true;
            set(parentfigure,'CurrentAxes',handle);
            move_axis = true;
            create_axis = false;
            if narg >= 5 && strcmpi(varargin{2},'PreventMove')
                preventMove = true;
                pvpairs = varargin(3:end);
            else
                pvpairs = varargin(2:end);
            end
        elseif strncmpi(arg,'replace',1)
            % passed in subplot(m,n,p,'replace')
            kill_siblings = 2; % kill nomatter what
        elseif strcmpi(arg,'align')
            % passed in subplot(m,n,p,'align')
            % since obeying position will remove the axes from the grid just set
            % useAutoLayout to false to skip adding it to the grid to start with
            useAutoLayout = true;%hier habe ich von false auf true geändert
            kill_siblings = 1; % kill if it overlaps stuff
        elseif strcmpi(arg,'v6')
            % passed in subplot(m,n,p,'v6')
            % since obeying position will remove the axes from the grid just set
            % useAutoLayout to false to skip adding it to the grid to start with
            warning(['MATLAB:', mfilename, ':DeprecatedV6Argument'],...
                ['The ''v6'' argument to %s is deprecated,',...
                ' and will no longer be supported in a future release.'], upper(mfilename));
            useAutoLayout = true;%hier habe ich von false auf true geändert
            kill_siblings = 1; % kill if it overlaps stuff
        else
            % passed in prop-value pairs
            kill_siblings = 1;
            pvpairs = varargin;
            par = find(strncmpi('Parent',pvpairs(1:2:end),6));
            if any(par)
                % If the parent is passed in explicitly, don't create a new figure
                % when the "NextPlot" property is set to "new" in the figure.
                explicitParent = true;
                parent = varargin{2*par(1)};
                parentfigure = ancestor(parent,'figure');
            end
        end
    else
        % Passed in "Position" syntax with P/V pairs
        % The arguments MUST be the string 'position' and a 4-element vector:
        if(strcmpi(nrows, 'position'))
            pos_size = size(ncols);
            if(pos_size(1) * pos_size(2) == 4)
                position = ncols;
                explicitPosition = true;
            else
                error(id('InvalidPositionParameter'),...
                    'Position must be of the form [left bottom width height].')
            end
        else
            error(id('UnknownOption'),'Unknown command option.')
        end
        kill_siblings = 1; % Kill overlaps here also.
        useAutoLayout = true;%hier habe ich von false auf true geändert
        pvpairs = [{thisPlot} varargin];
        par = find(strncmpi('Parent',pvpairs(1:2:end),6));
        if any(par)
            % If the parent is passed in explicitly, don't create a new figure
            % when the "NextPlot" property is set to "new" in the figure.
            explicitParent = true;
            parent = pvpairs{2*par(1)};
            parentfigure = ancestor(parent,'figure');
        end
    end
end

% if we recovered an identifier earlier, use it:
if ~isempty(handle) && ~move_axis
    parent = get(handle,'Parent');
    parentfigure = ancestor(handle,'figure');
    set(parentfigure,'CurrentAxes',handle);
else  % if we haven't recovered position yet, generate it from mnp info:
    if isempty(parent),
        parent = gcf;
        parentfigure = parent;
    end
    if isempty(position)
        if min(thisPlot) < 1
            error(id('SubplotIndexTooSmall'),'Illegal plot number.')
        elseif max(thisPlot) > ncols*nrows
            error(id('SubplotIndexTooLarge'),'Index exceeds number of subplots.');
        else

            row = (nrows-1) -fix((thisPlot-1)/ncols);
            col = rem (thisPlot-1, ncols);

            % get default axis position in normalized units
            % If we have checked this quanitity once, cache it.
            if ~isappdata(parentfigure,'SubplotDefaultAxesLocation')
                if ~strcmp(get(parentfigure,'defaultaxesunits'),'normalized')
                    tmp = axes;
                    set(tmp,'units','normalized')
                    def_pos = get(tmp,'position');
                    delete(tmp)
                else
                    def_pos = get(parentfigure,'DefaultAxesPosition');
                end
                setappdata(parentfigure,'SubplotDefaultAxesLocation',def_pos);
            else
                def_pos = getappdata(parentfigure,'SubplotDefaultAxesLocation');
            end

            % compute outerposition and insets relative to figure bounds
            rw = max(row)-min(row)+1;
            cw = max(col)-min(col)+1;
            width = def_pos(3)/(ncols - inset(1) - inset(3));
            height = def_pos(4)/(nrows - inset(2) - inset(4));
            inset = inset.*[width height width height];
            outerpos = [def_pos(1) + min(col)*width - inset(1), ...
                def_pos(2) + min(row)*height - inset(2), ...
                width*cw height*rw];

            % adjust outerpos and insets for axes around the outside edges
            if min(col) == 0
                inset(1) = def_pos(1);
                outerpos(3) = outerpos(1)+outerpos(3);
                outerpos(1) = 0;
            end
            if min(row) == 0,
                inset(2) = def_pos(2);
                outerpos(4) = outerpos(2)+outerpos(4);
                outerpos(2) = 0;
            end
            if max(col) == ncols-1,
                inset(3) = max(0,1-def_pos(1)-def_pos(3));
                outerpos(3) = 1-outerpos(1);
            end
            if max(row) == nrows-1,
                inset(4) = max(0,1-def_pos(2)-def_pos(4));
                outerpos(4) = 1-outerpos(2);
            end

            % compute inner position
            position = [outerpos(1:2) + inset(1:2),...
                outerpos(3:4) - inset(1:2) - inset(3:4)];

        end
    end
end

% kill overlapping siblings if mnp specifier was used:
nextstate = get(parentfigure,'nextplot');

if strncmp(nextstate,'replace',7)
    nextstate = 'add';
elseif strncmp(nextstate,'new',3)
    kill_siblings = 1;%hier habe ich von 0 auf 1 geändert
end

if(kill_siblings)
    if delay_destroy
        if nargout
            error(id('TooManyOutputs'),...
                'Function called with too many output arguments.')
        else
            set(parentfigure,'NextPlot','replace');
            return
        end
    end
    sibs = datachildren(parent);
    newcurrent = [];
    for i = 1:length(sibs)
        % Be aware that handles in this list might be destroyed before
        % we get to them, because of other objects' DeleteFcn callbacks...
        if(ishghandle(sibs(i),'axes'))
            units = get(sibs(i),'Units');
            sibpos = get(sibs(i),'Position');
            % If a legend or colorbar has resized the axes, use the original axes
            % position as the "Position" property:
            if ~explicitPosition
                if isappdata(sibs(i),'LegendColorbarExpectedPosition') && ...
                        isequal(getappdata(sibs(i),'LegendColorbarExpectedPosition'),get(sibs(i),'Position'))
                    inset = getappdata(sibs(i),'LegendColorbarOriginalInset');
                    if isempty(inset)
                        % during load the appdata might not be present
                        inset = get(get(sibs(i),'Parent'),'DefaultAxesLooseInset');
                    end
                    inset = offsetsInUnits(sibs(i),inset,'normalized',get(sibs(i),'Units'));
                    if strcmpi(get(sibs(i),'ActivePositionProperty'),'position')
                        pos = get(sibs(i),'Position');
                        loose = get(sibs(i),'LooseInset');
                        opos = getOuterFromPosAndLoose(pos,loose,get(sibs(i),'Units'));
                        if strcmp(get(sibs(i),'Units'),'normalized')
                            inset = [opos(3:4) opos(3:4)].*inset;
                        end
                        sibpos = [opos(1:2)+inset(1:2) opos(3:4)-inset(1:2)-inset(3:4)];
                    end
                end
            end
            if ~strcmp(units,'normalized')
                sibpos = hgconvertunits(parentfigure,sibpos,units,'normalized',parent);
            end
            intersect = 1;
            if((position(1) >= sibpos(1) + sibpos(3)-tol) || ...
                    (sibpos(1) >= position(1) + position(3)-tol) || ...
                    (position(2) >= sibpos(2) + sibpos(4)-tol) || ...
                    (sibpos(2) >= position(2) + position(4)-tol))
                intersect = 0;
            end
            if intersect
                % position is the proposed position of an axes, and
                % sibpos is the current position of an existing axes.
                % Since the bounding boxes of position and sibpos overlap,
                % we must determine whether to delete the sibling sibs(i)
                % whose normalized position is sibpos.
               
                % First of all, we check whether we must kill the sibling
                % "no matter what."
                if (kill_siblings == 2)
                    delete(sibs(i));
                   
                % If the proposed and existing axes overlap exactly, we do
                % not kill the sibling.  Rather we shall ensure later that
                % this sibling axes is set as the 'CurrentAxes' of its
                % parentfigure.
                   
                % Next we check for a partial overlap.
                elseif (any(abs(sibpos - position) > tol))
                    % The proposed and existing axes partially overlap.
                    % Since the proposed and existing axes could each be
                    % "grid-generated" or "explicitly-specified", we must
                    % consider four possibilities for the overlap of
                    % "proposed" vs. "existing", i.e.
                    % (1) "grid-generated" vs. "grid-generated"
                    % (2) "grid-generated" vs. "explicitly-specified"
                    % (3) "explicitly-specified" vs. "grid-generated"
                    % (4) "explicitly-specified" vs. "explicitly-specified"
                   
                    % If the position of the proposed axes is
                    % "explicitly-specified", then the only condition that
                    % avoids killing the sibling is an exact overlap.
                    % However, we know that the overlap is partial.
                    if (explicitPosition)
                        delete(sibs(i));
                    else
                        % We know that the position of the proposed axes is
                        % "grid-generated".
                       
                        grid = getappdata(parent,'SubplotGrid');
                        % The SubplotGrid maintains an array of axes
                        % handles, one per grid location.  Axes that span
                        % multiple grid locations do not store handles in
                        % the SubplotGrid.
                       
                        if isempty(grid) || ~any(grid(:) == sibs(i)) || ...
                                size(grid,1) ~= nrows || size(grid,2) ~= ncols || ...
                                ~isscalar(row) || ~isscalar(col)
                            % If the sibling cannot be found in the grid, we
                            % kill the sibling.  Otherwise, the proposed and
                            % existing axes are "grid-generated".  If we
                            % are changing the size of the grid, we kill
                            % the sibling.  Otherwise, "thisPlot" may be a
                            % vector of multiple grid locations, which
                            % causes a partial overlap between the proposed
                            % and existing axes, so we kill the sibling.
                           
                            % This check recognizes that there may be
                            % labels, colorbars, legends, etc. attached to
                            % the existing axes that have affected its
                            % position.  In such a case, we do not kill the
                            % sibling.
                            delete(sibs(i));
                        end
                    end
                end
                if ishghandle(sibs(i))
                    % if this axes overlaps the other one exactly then
                    if ~isempty(newcurrent) && ishghandle(newcurrent)
                        delete(newcurrent);
                    end
                    newcurrent = sibs(i);
                end
            end
        end
    end
    if ~isempty(newcurrent) && ishghandle(newcurrent)
        set(parentfigure,'CurrentAxes',newcurrent);
        create_axis = false;
    end
    set(parentfigure,'NextPlot',nextstate);
end

% create the axis:
if create_axis
    if strcmp(nextstate,'new') && ~explicitParent
        parent = figure;
        parentfigure = parent;
    end
    ax = axes('units','normal','Position',position,...
        'LooseInset',inset,'Parent',parent);
    % TODO: Get axes to accept position args on command line
    set(ax,'units',get(double(parentfigure),'defaultaxesunits'))
    if useAutoLayout
        addAxesToGrid(ax,nrows,ncols,row,col,position);
    end
    if ~isempty(pvpairs)
        set(ax,pvpairs{:});
    end
elseif move_axis && ~preventMove
    ax = handle;
    units = get(handle,'units');
    set(handle,'units','normal','Position',position,...
        'LooseInset',inset,'Parent',parent);
    set(handle,'units',units);
    if useAutoLayout
        addAxesToGrid(ax,nrows,ncols,row,col,position);
    end
    if ~isempty(pvpairs)
        set(handle,pvpairs{:});
    end
else
    % this should only happen with subplot(H)
    ax = get(parentfigure,'CurrentAxes');
end

% return identifier, if requested:
if(nargout > 0)
    theAxis = ax;
end

% Create subplot listeners to align plot boxes automatically
function createListeners(p,axlisth)
setappdata(p,'SubplotListeners',[])
fig = p;
if ~isequal(get(fig,'Type'),'figure')
    fig = ancestor(fig,'figure');
end
list = [...
    handle.listener(axlisth,findprop(axlisth(1),'Units'), ... % must be first
    'PropertyPostSet',@axesUnitsPostSet);
    handle.listener(axlisth,findprop(axlisth(1),'Units'), ...
    'PropertyPreSet',@axesUnitsPreSet);
    handle.listener(axlisth,findprop(axlisth(1),'Position'), ...
    'PropertyPostSet',@axesMoved);
    handle.listener(axlisth,findprop(axlisth(1),'ActivePositionProperty'), ...
    'PropertyPreSet',@axesMoved);
    handle.listener(axlisth,findprop(axlisth(1),'Parent'), ...
    'PropertyPreSet',@axesMoved);
    handle.listener(axlisth,'AxisInvalidEvent',{@subplotlayoutInvalid,p});
    handle.listener(handle(fig),'FigureUpdateEvent',{@subplotlayout,p})];
for k=1:length(axlisth)
    ax = axlisth(k);
    if ~isappdata(double(ax),'SubplotDeleteListener')
        setappdata(double(ax),'SubplotDeleteListener',...
            handle.listener(ax,'ObjectBeingDestroyed', ...
            @axesDestroyed));
    end
end
setappdata(p,'SubplotListeners',list)

% Add ax to a matrix of handles in the specified location.
% The grid is stored on the parent appdata.
% Also store the insets in ax appdata.
% Only stores the axes if it is in a 1-by-1 cell and
% the grid size matches any existing grid.
function addAxesToGrid(ax,nrows,ncols,row,col,position)
p = get(ax,'parent');
grid = getappdata(p,'SubplotGrid');
if isempty(grid)
    grid = zeros(nrows,ncols);
end
if any(size(grid) ~= [nrows ncols]), return; end
if length(row) ~= 1 || length(col) ~= 1, return; end
if round(row) ~= row || round(col) ~= col, return; end
if grid(row+1,col+1) == ax, return, end
grid(row+1,col+1) = ax;
list = grid(:);
list(list == 0) = []; % remove root
list(~ishghandle(list)) = []; % remove invalid handles
createListeners(p,handle(list));
setappdata(p,'SubplotGrid',grid)
setappdata(ax,'SubplotPosition',position); % normalized
subplotlayoutInvalid(handle(ax),[],p);

% Remove ax from grid of subplots in p
function removeAxesFromGrid(p,ax)
grid = getappdata(p,'SubplotGrid');
if ~isempty(grid)
    n = grid == ax;
    if any(n(:))
        grid(n) = 0;
        list = grid(:);
        list(list == 0) = []; % remove root
        list(~ishghandle(list)) = [];
        if isempty(list)
            rmappdata(p,'SubplotListeners');
            rmappdata(p,'SubplotGrid');
        else
            setappdata(p,'SubplotGrid',grid);
        end
    end
end

% Callback when axis moves to remove it from subplot layout grid
function axesMoved(hSrc,evdata) %#ok
ax = double(evdata.affectedObject);
% If the legend or colorbar is causing the move, do not remove the axes
% from the subplot grid. Do, however, update it's cached position:
if (isappdata(ax,'inLayout') && ~isempty(getappdata(ax,'inLayout'))) || ...
    isappdata(ax,'LegendColorbarReclaimSpace')
    setappdata(ax,'SubplotPosition',get(ax,'Position'));
else
    removeAxesFromGrid(get(ax,'Parent'),ax);
end

% Callback when axis changes units
function axesUnitsPreSet(hSrc,evdata) %#ok
ax = double(evdata.affectedObject);
p = get(ax,'Parent');
list = getappdata(p,'SubplotListeners');
if ~isempty(list)
    set(list(2:end),'enable','off');
end

% Callback when axis done changing units
function axesUnitsPostSet(hSrc,evdata) %#ok
ax = double(evdata.affectedObject);
p = get(ax,'Parent');
list = getappdata(p,'SubplotListeners');
if ~isempty(list)
    set(list(2:end),'enable','on');
end

% Callback when axis destroyed
function axesDestroyed(hSrc,evdata) %#ok
ax = double(hSrc);
p = get(ax,'Parent');
if strcmp(get(p,'BeingDeleted'),'off')
    removeAxesFromGrid(p,ax);
elseif isappdata(p,'SubplotListeners')
    rmappdata(p,'SubplotListeners');
    rmappdata(p,'SubplotGrid');
end

function str = id(str)
str = ['MATLAB:subplot:' str];

%----------------------------------------------------------------%
% Convert units of offsets like LooseInset or TightInset
% Note: Copied from legendcolorbarlayout.m
function out = offsetsInUnits(ax,in,from,to)
fig = ancestor(ax,'figure');
par = get(ax,'Parent');
p1 = hgconvertunits(fig,[0 0 in(1:2)],from,to,par);
p2 = hgconvertunits(fig,[0 0 in(3:4)],from,to,par);
out = [p1(3:4) p2(3:4)];

%----------------------------------------------------------------%
% Compute reference OuterPos from pos and loose. Note that
% loose insets are relative to outerposition
% Note: Copied from legendcolorbarlayout.m
function outer = getOuterFromPosAndLoose(pos,loose,units)
if strcmp(units,'normalized')
    % compute outer width and height and normalize loose to them
    w = pos(3)/(1-loose(1)-loose(3));
    h = pos(4)/(1-loose(2)-loose(4));
    loose = [w h w h].*loose;
end
outer = [pos(1:2)-loose(1:2) pos(3:4)+loose(1:2)+loose(3:4)];


 


Ich bitte nochmal um Hilfe.

Habt vielen Dank.
Viele Grüße,
Max
Private Nachricht senden Benutzer-Profile anzeigen
 
mat_macs
Themenstarter

Forum-Anfänger

Forum-Anfänger


Beiträge: 26
Anmeldedatum: 27.09.10
Wohnort: ---
Version: ---
     Beitrag Verfasst am: 27.04.2012, 19:03     Titel:
  Antworten mit Zitat      
Kann mir denn keiner sagen, wie ich die OuterPosition zur ActivePositionProperty mache?

Viele Grüße,
Max
Private Nachricht senden Benutzer-Profile anzeigen
 
Harald
Forum-Meister

Forum-Meister


Beiträge: 24.501
Anmeldedatum: 26.03.09
Wohnort: Nähe München
Version: ab 2017b
     Beitrag Verfasst am: 27.04.2012, 19:11     Titel:
  Antworten mit Zitat      
Hallo,

bitte etwas Geduld. Gerade wenn das Wochenende vor der Tür steht und die Sonne scheint, sitzen vielleicht nicht haufenweise Leute vor dem Rechner Wink

Eine dringende Empfehlung: arbeite mehr mit der Dokumentation als zu versuchen, das Innenleben von Funktionen im Detail zu verstehen.

Was spricht dagegen, die Position des Koordinatensystems einfach explizit anzugeben? Das sollte doch deutlich einfacher sein?

Grüße,
Harald
Private Nachricht senden Benutzer-Profile anzeigen
 
mat_macs
Themenstarter

Forum-Anfänger

Forum-Anfänger


Beiträge: 26
Anmeldedatum: 27.09.10
Wohnort: ---
Version: ---
     Beitrag Verfasst am: 27.04.2012, 20:54     Titel:
  Antworten mit Zitat      
Ja also danke für die Rückmeldung. Die Dokumentation hat mich ja erst auf die Idee mit der OuterPosition gebracht. Aber wie ich das dann definiere, verstehe ich noch nicht...

Viele Grüße,
Max
Private Nachricht senden Benutzer-Profile anzeigen
 
Harald
Forum-Meister

Forum-Meister


Beiträge: 24.501
Anmeldedatum: 26.03.09
Wohnort: Nähe München
Version: ab 2017b
     Beitrag Verfasst am: 27.04.2012, 22:17     Titel:
  Antworten mit Zitat      
Hallo,

z.B. so:

Code:
subplot(2,1,1,'ActivePositionProperty', 'OuterPosition')


Grüße,
Harald
Private Nachricht senden Benutzer-Profile anzeigen
 
mat_macs
Themenstarter

Forum-Anfänger

Forum-Anfänger


Beiträge: 26
Anmeldedatum: 27.09.10
Wohnort: ---
Version: ---
     Beitrag Verfasst am: 28.04.2012, 11:40     Titel:
  Antworten mit Zitat      
Grüß dich Harald,

vielen Dank für deine Antwort. Ich habe das so jetzt erstmal importiert und jetzt wird nur noch ein Axes sozusagen angezeigt (nur das rechte). Aber ich vermute, dass das an meiner Schleife liegt , welche in meinem Programm enthalten ist:
Code:


subplot(1,length(idx),i,'ActivePositionProperty','OuterPosition');

 


Ich werde mich weiter drum kümmern, aber vielen Dank schon für den Vorschlag!

Viele Grüße,
Max
Private Nachricht senden Benutzer-Profile anzeigen
 
Harald
Forum-Meister

Forum-Meister


Beiträge: 24.501
Anmeldedatum: 26.03.09
Wohnort: Nähe München
Version: ab 2017b
     Beitrag Verfasst am: 28.04.2012, 12:36     Titel:
  Antworten mit Zitat      
Hallo,

ich würde eher mit AXES als mit SUBPLOT arbeiten, wenn die Positionen angepasst werden sollen.

Wenn weitere Hilfe notwendig ist, wäre ein lauffähiges Testbeispiel hilfreich.

Grüße,
Harald
Private Nachricht senden Benutzer-Profile anzeigen
 
mat_macs
Themenstarter

Forum-Anfänger

Forum-Anfänger


Beiträge: 26
Anmeldedatum: 27.09.10
Wohnort: ---
Version: ---
     Beitrag Verfasst am: 30.04.2012, 11:49     Titel:
  Antworten mit Zitat      
Hallo Harald,
danke dir! Nach intensiver Beschäftigung mit AXES habe ich es herausbekommen.

Code:


axes('position',[-0.2+i*0.3 .15 .8 .8]);

 


Damit werden alle Subplots schön nebeneinander angezeigt.

Vielen Dank für deine Hilfe!

Viele Grüße,
Max!
Private Nachricht senden Benutzer-Profile anzeigen
 
Harald
Forum-Meister

Forum-Meister


Beiträge: 24.501
Anmeldedatum: 26.03.09
Wohnort: Nähe München
Version: ab 2017b
     Beitrag Verfasst am: 30.04.2012, 12:10     Titel:
  Antworten mit Zitat      
Hallo,

das hatte ich an sich in meiner ersten Antwort vorgeschlagen Wink

Grüße,
Harald
Private Nachricht senden Benutzer-Profile anzeigen
 
mat_macs
Themenstarter

Forum-Anfänger

Forum-Anfänger


Beiträge: 26
Anmeldedatum: 27.09.10
Wohnort: ---
Version: ---
     Beitrag Verfasst am: 15.05.2012, 15:45     Titel:
  Antworten mit Zitat      
Hallo Harald und hallo Community,

ich muss das Thema leider doch nochmal aufrollen, denn mit AXES ist es dch noch nicht gelöst. Habe jetzt die Breite meiner Axes geändert und schon liegt das YLabel des jeweils rechteren Axes wieder im Axes des linkeren, also das in der Mitte wird von rechts überlagert und das ganz links wird vom mittleren überlagert.
Es muss doch möglich sein, dass man es so definiert, dass in meiner for-Schleife Axes1 ganz links positioniert wird und Axes1+i dann immer erst dort anfängt, wo das vorherige aufhört.

Hier mein Code für mein eigentliches Programm:
Code:



%% plot settings
SHOW_MAGNITUDES = 1;
FIGURE_SIZE = [1280,800];

clf;
clc;
clear pset;
pset.FontSize = 10;
pset.LineWidth = 1.5;
pset.Box = 'on';
pset.Title.String = '';
pset.Title.FontSize = 12;
pset.Title.FontWeight = 'bold';
pset.colorbar.FontSize = 10;
pset.colorbar.Xlabel.FontWeight = 'bold';
pset.colorbar.Xlabel.FontSize = 12;
pset.colorbar.Xlabel.String = {'Beschleunigungs-';'pegel in dB'}; %für Beschleunigungsaufnehmer
%pset.colorbar.Xlabel.String = {'Schalldruck-};{pegel in dB'};    %für Mikrofonaufnahmen
pset.Xlabel.FontWeight = 'demi';
pset.Ylabel.FontWeight = pset.Xlabel.FontWeight;
pset.Xlabel.FontSize = 16;
pset.Ylabel.FontSize = pset.Xlabel.FontSize;
pset.Xlabel.String = 'Zeit in s';
pset.Ylabel.String = 'Frequenz in Hz';
pset.YScale = 'log';
[b]pset.Position.width = 0.21;
[/b]

%% load file
[fileName, fileDir, FileIndex] = uigetfile('C:\Users\....\Desktop\GB Sounddesign Messungen\Siki-Day1\*.csv','Please select Measurement!');
if isequal(fileName,0)
    return
end
[measMat,sampleFreq,numChannels] = ...
    readArtemisMeas(fullfile(fileDir,fileName));
dlg_title   = ['Please select Channel 1-' num2str(numChannels)];
prompt      = {'Channel'};  %Bezeichnung des Textfeldes
def         = {'1,2,3'};        %Wahl der Kanäle
answer      = inputdlg(prompt,dlg_title,1,def);
%channelIdx  = str2double(answer);
set(gcf,'Name',fileName(1:end-4),'NumberTitle','off');

%% calc fft vs time
%_____________
idx=str2num(answer{:});
for i=1:length(idx)
   
    signalVec = measMat(:,1+idx(i));
   
    %cutOffFreq = 60;
    %signalVec = tpFiltfilt(signalVec, sampleFreq, cutOffFreq, cutOffFreq+0.5);
    %signalVec = hpFiltfilt(signalVec, sampleFreq, cutOffFreq, cutOffFreq+0.5);
   
    winLen      = 4*2048;%1024 2048 4096
    overLap     = 0.5*winLen;
    %ref         = 2e-5; %for sound
    ref         = 1e-6; %for vib
    [specdB,fvec,tvec] =

get_Spectrogramm(signalVec,overLap,winLen,sampleFreq,ref);
   
    %% plot spectrogramm
    fStart      = 0;
    fEnd        = 1000;
    magStart    = 85;
    magEnd      = 120;
    specRef     = 1e-6;
   

    [b]axes('position',[-0.2+i*0.3 .17 .8 .8]);[/b]
    set(gca,'ActivePropertyPosition','OuterPosition');
    show_Spectrogramm(tvec,fvec,specdB,fStart,fEnd,magStart,magEnd,specRef);
    bez     = ['x' 'y' 'z'];
    text(max(tvec)-0.8,720,num2str(bez(1,i)),'FontSize',18,'HorizontalAlignment','center','BackgroundColor',[1 1 1]);
    %pset.Ylabel.Position = [-0.2+i*0.3 .17 .8 .8];
    view(0,90);
   
   
    applyPlotSettings(gca,pset);
   
    if SHOW_MAGNITUDES == 0
        delete(findobj(gcf,'tag','Colorbar')) ;
    end
   
    % set(gcf,'Position',[100,100,FIGURE_SIZE(1),FIGURE_SIZE(2)]);
    % set(gcf,'PaperPositionMode','auto');
    %print ('-f', '-dmeta', ['Beschleunigungsspektrum über die Zeit ' fileName '.jpg']);
    print('-dpng','-r600',['C:\Users\....\Desktop\GB Sounddesign Messungen\Siki-Day1\',fileName(1:end-4),'.png']);

   
end

 


get_Spectogramm und show_Spectogramm sind zwei weitere vorgefertigte m-Files, bei denen ich aber nichts verändern darf.

Hat jemand einen Lösungsvorschlag?

Nochmal zu dem ActivePositionProperty: ich verstehe einfach nicht, wie man das eingeben muss, damit die einzelnen Axes inkl. deren Labels sich nicht mehr überlagern.

Bitte helft mir,
habt vielen Dank!

Euer Max


Edit: Wenn ich die Breite (Width) meiner Axes ändere, siehts schnell mal so wie im Anhang aus:

Renault Fluence Besch_0-30_gut ( 0.00-12.40 s).png
 Beschreibung:

Download
 Dateiname:  Renault Fluence Besch_0-30_gut ( 0.00-12.40 s).png
 Dateigröße:  1.54 MB
 Heruntergeladen:  993 mal
Private Nachricht senden Benutzer-Profile anzeigen
 
Harald
Forum-Meister

Forum-Meister


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

da das ja für mich nicht reproduzierbar ist, kann ich dir nur empfehlen, bei
Code:
axes('position',[-0.2+i*0.3 .17 .8 .8])

an den Parametern zu drehen, z.B. statt 0.17 kleinere Werte.

Grüße,
Harald
Private Nachricht senden Benutzer-Profile anzeigen
 
Neues Thema eröffnen Neue Antwort erstellen

Gehe zu Seite 1, 2  Weiter

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 - 2025 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.