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

Abspeichern einer Grafik

 

MaFam
Forum-Meister

Forum-Meister


Beiträge: 799
Anmeldedatum: 02.05.12
Wohnort: ---
Version: R2009b
     Beitrag Verfasst am: 01.08.2012, 20:36     Titel: Abspeichern einer Grafik
  Antworten mit Zitat      
Hallo,

ich versuche mit folgendem Code, den Inhalt des Axes-Controls als Bild zu speichern.

Code:
[FileName,PathName] = uiputfile({'*.jpg;*.tif;*.png;*.gif','All Image Files';...
          '*.*','All Files' },'Save Image',...
          [pwd,'\newfile.jpg'])

set(handles.Approximation,'CurrentAxes',handles.axesapprox);  
saveas(gca,[PathName,FileName])


Der Codes sorgt aber dafür, dass die gesamte GUI als Bild abgespeichert wird.

Woran liegt das und wie kann ich das Problem lösen?

Grüße, Marc
Private Nachricht senden Benutzer-Profile anzeigen


Bluesmaster
Forum-Century

Forum-Century



Beiträge: 203
Anmeldedatum: 13.11.11
Wohnort: Gera
Version: 2012a
     Beitrag Verfasst am: 02.08.2012, 19:10     Titel:
  Antworten mit Zitat      
saveas kann glaube ich nur figures

vielleicht hilft dir das tool:

http://www.mathworks.com/matlabcent.....eexchange/23629-exportfig




Gruß

Blues
Private Nachricht senden Benutzer-Profile anzeigen
 
MaFam
Themenstarter

Forum-Meister

Forum-Meister


Beiträge: 799
Anmeldedatum: 02.05.12
Wohnort: ---
Version: R2009b
     Beitrag Verfasst am: 02.08.2012, 19:23     Titel:
  Antworten mit Zitat      
Danke dir! Das probiere ich unbedingt mal aus.
Private Nachricht senden Benutzer-Profile anzeigen
 
MaFam
Themenstarter

Forum-Meister

Forum-Meister


Beiträge: 799
Anmeldedatum: 02.05.12
Wohnort: ---
Version: R2009b
     Beitrag Verfasst am: 05.08.2012, 11:44     Titel:
  Antworten mit Zitat      
So, ich habe nun die Skripts im Link getestet. Ich verwende fh = isolate_axes(ah, vis) in Verbindung mit fh = copyfig(fh). Leider erhalte ich nicht das gewünschte Ergebnis. Siehe angehängte Grafik...

Der Bereich ist nur rechts ausgefüllt. Ich würde aber gerne die Grafik über den gesamten Bereich gestreckt sehen.

newfile.jpg
 Beschreibung:

Download
 Dateiname:  newfile.jpg
 Dateigröße:  37.56 KB
 Heruntergeladen:  518 mal
Private Nachricht senden Benutzer-Profile anzeigen
 
MaFam
Themenstarter

Forum-Meister

Forum-Meister


Beiträge: 799
Anmeldedatum: 02.05.12
Wohnort: ---
Version: R2009b
     Beitrag Verfasst am: 05.08.2012, 13:41     Titel:
  Antworten mit Zitat      
Hm, die logische Konsequenz ist dann wohl, die Größe über die Position-Eigenschaft anzupassen. Das würde ich natürlich gerne automatisch relativ zum Axes-Handle geschehen lassen. Wie gehe ich da geschickt vor?

Zuletzt bearbeitet von MaFam am 05.08.2012, 14:15, insgesamt einmal bearbeitet
Private Nachricht senden Benutzer-Profile anzeigen
 
MaFam
Themenstarter

Forum-Meister

Forum-Meister


Beiträge: 799
Anmeldedatum: 02.05.12
Wohnort: ---
Version: R2009b
     Beitrag Verfasst am: 05.08.2012, 14:11     Titel:
  Antworten mit Zitat      
Anpassung der isolate_axes(ah, vis) brachte Erfolg. Die entsprechenden Stellen sind gekennzeichnet. Schön ist was anderes, aber es funktioniert immerhin...

Code:

%ISOLATE_AXES Isolate the specified axes in a figure on their own
%
% Examples:
%   fh = isolate_axes(ah)
%   fh = isolate_axes(ah, vis)
%
% This function will create a new figure containing the axes specified, and
% also their associated legends and colorbars. The axes specified must all
% be in the same figure, but they will generally only be a subset of the
% axes in the figure.
%
% IN:
%    ah - An array of axes handles, which must come from the same figure.
%    vis - A boolean indicating whether the new figure should be visible.
%          Default: false.
%
% OUT:
%    fh - The handle of the created figure.

% Copyright (C) Oliver Woodford 2011-2012

% Thank you to Rosella Blatt for reporting a bug to do with axes in GUIs
% 16/3/2012 Moved copyfig to its own function. Thanks to Bob Fratantonio
% for pointing out that the function is also used in export_fig.m.

function fh = isolate_axes(ah, vis)
% Make sure we have an array of handles
if ~all(ishandle(ah))
    error('ah must be an array of handles');
end
% Check that the handles are all for axes, and are all in the same figure
fh = ancestor(ah(1), 'figure');
nAx = numel(ah);
for a = 1:nAx
    if ~strcmp(get(ah(a), 'Type'), 'axes')
        error('All handles must be axes handles.');
    end
    if ~isequal(ancestor(ah(a), 'figure'), fh)
        error('Axes must all come from the same figure.');
    end
end
% Tag the axes so we can find them in the copy
old_tag = get(ah, 'Tag');
if nAx == 1
    old_tag = {old_tag};
end
set(ah, 'Tag', 'ObjectToCopy');
% Create a new figure exactly the same as the old one
fh = copyfig(fh); %copyobj(fh, 0);

% Benutzerdefinierte Anpassung:
% -------------------------------------------------------------------------
posfig=get(fh, 'Position');
set(fh, 'Position', [posfig(1), posfig(2), 1/2*posfig(3), posfig(4)]);
% -------------------------------------------------------------------------

if nargin < 2 || ~vis
    set(fh, 'Visible', 'off');
end
% Reset the axes tags
for a = 1:nAx
    set(ah(a), 'Tag', old_tag{a});
end
% Find the objects to save
ah = findall(fh, 'Tag', 'ObjectToCopy');
if numel(ah) ~= nAx
    close(fh);
    error('Incorrect number of axes found.');
end
% Set the axes tags to what they should be
for a = 1:nAx
    set(ah(a), 'Tag', old_tag{a});
   
    % Benutzerdefinierte Anpassung:
    % ---------------------------------------------------------------------
    posaxes=get(ah(a), 'Position');
    set(ah(a), 'Position', [0.05 ,posaxes(2),2*posaxes(3),posaxes(4)]);
    % ---------------------------------------------------------------------
   
end
% Keep any legends and colorbars which overlap the subplots
lh = findall(fh, 'Type', 'axes', '-and', {'Tag', 'legend', '-or', 'Tag', 'Colorbar'});
nLeg = numel(lh);
if nLeg > 0
    ax_pos = get(ah, 'OuterPosition');
    if nAx > 1
        ax_pos = cell2mat(ax_pos(:));
    end
    ax_pos(:,3:4) = ax_pos(:,3:4) + ax_pos(:,1:2);
    leg_pos = get(lh, 'OuterPosition');
    if nLeg > 1;
        leg_pos = cell2mat(leg_pos);
    end
    leg_pos(:,3:4) = leg_pos(:,3:4) + leg_pos(:,1:2);
    for a = 1:nAx
            % Overlap test
            ah = [ah; lh(leg_pos(:,1) < ax_pos(a,3) & leg_pos(:,2) < ax_pos(a,4) &...
                         leg_pos(:,3) > ax_pos(a,1) & leg_pos(:,4) > ax_pos(a,2))];
    end
end
% Get all the objects in the figure
axs = findall(fh);
% Delete everything except for the input axes and associated items
delete(axs(~ismember(axs, [ah; allchildren(ah); allancestors(ah)])));
return

function ah = allchildren(ah)
ah = allchild(ah);
if iscell(ah)
    ah = cell2mat(ah);
end
ah = ah(:);
return

function ph = allancestors(ah)
ph = [];
for a = 1:numel(ah)
    h = get(ah(a), 'parent');
    while h ~= 0
        ph = [ph; h];
        h = get(h, 'parent');
    end
end
return
 


newfile.pdf
 Beschreibung:

Download
 Dateiname:  newfile.pdf
 Dateigröße:  4.59 KB
 Heruntergeladen:  425 mal
Private Nachricht senden Benutzer-Profile anzeigen
 
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 - 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.