Mein MATLAB Forum - goMatlab.de

Mein MATLAB Forum

 
Gast > Registrieren       Autologin?   
Bücher:

Studierende:
Praktikant Toolentwicklung Matlab (m/w)
Branche: Beratung, Expertise, Fahrzeugtechnik, Fahrzeugteile, Technische Dienstleistungen
MBtech Group GmbH & Co. KGaA - Fellbach

Abschlussarbeit / Praktikum: Entwicklung Matlab (m/w)
Branche: Informationstechnologie, Elektrotechnik, Elektronik
GIGATRONIK Technologies GmbH - Ulm

Studentischer Mitarbeiter (m/w) - DevOps / Toolentwicklung
Branche: mehrere
IAV GmbH - Ingenieurgesellschaft Auto und Verkehr - Berlin

Praktikant (m/w) Bereich Konzernvorausentwicklung - Aktoren sicherheitsrelevanter Anwendungen
Branche: Fahrzeugtechnik, Fahrzeugteile, Maschinentechnik, Industrietechnik
MAHLE International GmbH - Stuttgart

Praktikum - Softwareentwicklung Java
Branche: mehrere
IAV GmbH - Ingenieurgesellschaft Auto und Verkehr - Dresden, Gifhorn

weitere Angebote

Partner:


Vermarktungspartner


Forum
      Option
[Erweitert]
  • Diese Seite per Mail weiterempfehlen
     


Gehe zu:  
Neues Thema eröffnen Neue Antwort erstellen

Figure plot automatisiert

 

Henrik123
Forum-Fortgeschrittener

Forum-Fortgeschrittener


Beiträge: 81
Anmeldedatum: 25.01.17
Wohnort: ---
Version: 2011a, 2017a
     Beitrag Verfasst am: 17.10.2017, 16:07     Titel: Figure plot automatisiert
  Antworten mit Zitat      
Hallo. Ich versuche gerade meine Programm zum laufen zu bekommen. Es besteht aus drei Teilen.
    1. Definieren der Konstanten und Vektoren
    2. Lösung der Differentialgleichungen
    3. Plotten der Daten


Ich plotte vier Grafiken mit jeweils zwei subplots. In jedem Subplot befinden sich fünf Kurven. Dazu habe ich schon einige fragen in diesem Forum gestellt. Das klappt alles soweit auch super. Nun möchte ich mit einer for loop die Grafiken plotten. Leider übernimmt er die Werte für die Kurven nicht.

Hier einmal das gesammte Skript.

Code:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% NOT IMPORTANT %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Constants
% Main
t = 4;      % Amount of pictures
g = 1;      % Gain middle ear
b = 0.4;    % Relation of displacement ?_b zu  ?_p
gamma = 1;  % Gain of OHC (for death ear: gamma = 0) (default value: gamma = 1)
rho = 1;    % Density of cochlea fluid, unit (dyn*cm^-3)
nf = 5;     % Amount of curves in the figure, test frequencies

% Dimension of Cochlea
L = 3.5;      % Length of Cochlea, unit (cm)
H = 0.1;      % Heigth of Cochlea, unit (cm)
W = 0.1;      % Width of Cochlea, unit (cm)
N = 251;      % Amount of Cochlea partitions

% Arrays for data
x = transpose(linspace(0,L,N));     % Vector of distance for Cochlea partitions
o = ones(N-1,1);            
P = zeros(N,nf);            % Vector of pressure for Cochlea partitions, unit (dyn*cm^-2)
Yb = zeros(N,nf);           % Vector of admittance for Cochlea partitions, unit (dyn*s*cm^-3)
Db = zeros(N,nf);           % Vector of BM displacement for Cochlea partitions, unit (cm)
Dh = zeros(N,nf);           % Vector of OHC displacement for Cochlea partitions, unit (cm)

% BM: stiffness, damping und mass
k1 = 1.1e9*exp(-4*x);       % stiffness, unit (dyn*cm^-3)
c1 = 20+1500*exp(-2*x);     % damping, unit (dyn*s*cm^-3)
m1 = 0.003;                 % mass, unit (g*cm^-2)
k2 = 7e6*exp(-4.4*x);
c2 = 10*exp(-2.2*x);
m2 = 0.0005;
k3 = 1e7*exp(-4*x);
c3 = 2*exp(-0.8*x);
k4 = 6.15e8*exp(-4*x);
c4 = 1040*exp(-2*x);

% Middle ear: stiffness, damping und mass
km = 2.1e5;
cm = 400;
mm = 0.045;
As = 0.01;          % Area of the stapes, unit (cm^2)
Am = 0.35;
Gm = 0.5;
Pe = 2.848e-4;      % Pressure of the ear drum, unit (dyn*cm^-2)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% HERE IT STARTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Define titles and axis length
devTitle = {'Pressure','Impedance','BM displacement', 'OHC displacement'};
C = {[0 L -120 0],[0 L -1 1];
    [0 L -100 20], [0 L -5 1];
    [0 L -40 80], [0 L -5 1];
    [0 L -100 20],[0 L -5 1];
    };

%% Compute data
f = 50;
dx = L/(N-1);       % Equation A1
Ap = b/g;
for J = 1:nf,
    f = f*3;
    s = 2i*pi*f;
    srd = 2*s*rho*dx;
    % Impedance
    z1 = k1/s+c1+m1*s;
    z2 = k2/s+c2+m2*s;
    z3 = k3/s+c3;
    z4 = k4/s+c4;
    Zb = z1+z2.*(z3-gamma*z4)./(z2+z3);
    Zp = Zb/Ap;      %  Equation 12
    hc = z2./(z2+z3);Q = zeros(N,1);
    % Middle ear
    Zm = km/s+cm+mm*s;
    ame = -srd*As/(W*H*Zm);          % Equation A2
    pme = ame*(Am/(Gm*As))*Pe;       % Equation A3
    % Solution of pressure for middle ear
    Q = zeros(N,1);
    Q(1) = pme;
    a = (s*rho*dx*dx/(H))*(Zp.^(-1));
    A = diag(2+a,0)+diag(-o,1)+diag(-o,-1);
    A(1,1) = 1+ame;
    p = A\Q;
    P(:,J) = p/Pe;
    Yb(:,J) = Zb.^(-1);
    Db(:,J) = ((p./(Zb*g))./s)*1e7;
    Dh(:,J) = hc.*Db(:,J);

      % Create list for legend
      list{J} = [num2str(f) ' Hz'];

      % Combine results for automated plotting
      for i = 1:t;
          if i == 1
              Results{i,J} = P(:,J);
          elseif i == 2
              Results{i,J} = Yb(:,J);
          elseif i == 3
              Results{i,J} = Db(:,J);
          else
              Results{i,J} = Dh(:,J);
          end
      end
  end

xx = x;
tpi = 2*pi;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Plotting data %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

J=1;
i=1

for J = 1:nf;
    for i = 1:t  
    %% Print Figures
    figure(i);clf;

      % Plot data
      ax1 = subplot(211);
      plot(xx,real(20*log10(cell2mat(Results(i,J)))));
      axis(cell2mat(C(i,1)));
      title(devTitle(i));
      ax2 = subplot(212);
      plot(xx,unwrap(imag(log(cell2mat(Results(i,J)))))/tpi);
      axis(cell2mat(C(i,2)));

      % Set Ylabel for subplots
      hLabel1 = ylabel(ax1,'Amplitude in dB');
      hLabel2 = ylabel(ax2,'Phase in \pi');
      pos1 = get(hLabel1, 'Position');
      pos2 = get(hLabel2, 'Position');
      newX = min(pos1(1), pos2(1));
      pos1(1) = newX;
      pos2(1) = newX;
      set(hLabel1, 'Position', pos1);
      set(hLabel2, 'Position', pos2);

      % Set axis value
      LY1 = get(ax1,'YLim');
      Bildhoehe1 = get(gcf);
      NumTicksY1 = abs((LY1(1)-LY1(2))/20);
      set(ax1,'YTick',linspace(LY1(1),LY1(2),NumTicksY1+1));
      LY2 = get(ax2,'YLim');
      Bildhoehe2 = get(ax2, 'position');
      NumTicksY2 = abs((LY2(1)-LY2(2))/1);
      set(ax2,'YTick', linspace(LY2(1),LY2(2),NumTicksY2+1));

      % Xlabel here
      xlabel('Displacement in cm');

      % Legend here
      AX = legend(list,'Location','southoutside', 'orientation', 'horizontal');

      % Set figure heigth  
      AX.Position(1:2) = [0.08, 0.0] ;             % Move legend down and center a bit.
      ax2.Position(4) = ax1.Position(4) ;          % Set height axes 2 = height axes 1.
      ax1.Position(2) = ax1.Position(2)+0.01 ;     % Move axes 1 up a notch.
      ax2.Position(2) = ax2.Position(2)-0.11 ;     % Move axes 2 down.


Man sieht die Programmteile wie figure, plot und axes haben entsprechend einen Zähler erhalten. Außerdem achte ich auf die Form zwischen cell array und Dimension der übergebenen Vektoren.

Die Fehlermeldung ist:
Code:
Warning: Ignoring extra legend entries.
> In legend>set_children_and_strings (line 674)
  In legend>make_legend (line 346)
  In legend (line 294)
  In english (line 156)
Warning: Ignoring extra legend entries.
> In legend>set_children_and_strings (line 674)
  In legend>make_legend (line 346)
  In legend (line 294)
  In english (line 156)
Warning: Ignoring extra legend entries.
> In legend>set_children_and_strings (line 674)
  In legend>make_legend (line 346)
  In legend (line 294)
  In english (line 156)
Warning: Ignoring extra legend entries.
> In legend>set_children_and_strings (line 674)
  In legend>make_legend (line 346)
  In legend (line 294)
  In english (line 156)
Warning: Ignoring extra legend entries.
> In legend>set_children_and_strings (line 674)
  In legend>make_legend (line 346)
  In legend (line 294)
  In english (line 156)
Warning: Ignoring extra legend entries.
> In legend>set_children_and_strings (line 674)
  In legend>make_legend (line 346)
  In legend (line 294)
  In english (line 156)
Warning: Ignoring extra legend entries.
> In legend>set_children_and_strings (line 674)
  In legend>make_legend (line 346)
  In legend (line 294)
  In english (line 156)
Warning: Ignoring extra legend entries.
> In legend>set_children_and_strings (line 674)
  In legend>make_legend (line 346)
  In legend (line 294)
  In english (line 156)
Warning: Ignoring extra legend entries.
> In legend>set_children_and_strings (line 674)
  In legend>make_legend (line 346)
  In legend (line 294)
  In english (line 156)
Warning: Ignoring extra legend entries.
> In legend>set_children_and_strings (line 674)
  In legend>make_legend (line 346)
  In legend (line 294)
  In english (line 156)
Warning: Ignoring extra legend entries.
> In legend>set_children_and_strings (line 674)
  In legend>make_legend (line 346)
  In legend (line 294)
  In english (line 156)
Warning: Ignoring extra legend entries.
> In legend>set_children_and_strings (line 674)
  In legend>make_legend (line 346)
  In legend (line 294)
  In english (line 156)
Warning: Ignoring extra legend entries.
> In legend>set_children_and_strings (line 674)
  In legend>make_legend (line 346)
  In legend (line 294)
  In english (line 156)
Warning: Ignoring extra legend entries.
> In legend>set_children_and_strings (line 674)
  In legend>make_legend (line 346)
  In legend (line 294)
  In english (line 156)
Warning: Ignoring extra legend entries.
> In legend>set_children_and_strings (line 674)
  In legend>make_legend (line 346)
  In legend (line 294)
  In english (line 156)
Warning: Ignoring extra legend entries.
> In legend>set_children_and_strings (line 674)
  In legend>make_legend (line 346)
  In legend (line 294)
  In english (line 156)
Warning: Ignoring extra legend entries.
> In legend>set_children_and_strings (line 674)
  In legend>make_legend (line 346)
  In legend (line 294)
  In english (line 156)
Warning: Ignoring extra legend entries.
> In legend>set_children_and_strings (line 674)
  In legend>make_legend (line 346)
  In legend (line 294)
  In english (line 156)
Warning: Ignoring extra legend entries.
> In legend>set_children_and_strings (line 674)
  In legend>make_legend (line 346)
  In legend (line 294)
  In english (line 156)
Warning: Ignoring extra legend entries.
> In legend>set_children_and_strings (line 674)
  In legend>make_legend (line 346)
  In legend (line 294)
  In english (line 156)
Private Nachricht senden Benutzer-Profile anzeigen


Stonewall
Forum-Newbie

Forum-Newbie


Beiträge: 7
Anmeldedatum: 10.07.17
Wohnort: ---
Version: ---
     Beitrag Verfasst am: 18.10.2017, 19:56     Titel:
  Antworten mit Zitat      
Eventuell fehlt am Ende etwas.

Wenn ich 2 fehlende End Statements hinzufüge, bekomme ich

Code:
Attempt to reference field of non-structure array.

Error in Untitled (line 160)
      ax2.Position(4) = ax1.Position(4) ;          % Set height axes 2 =
      height axes 1.
 
Private Nachricht senden Benutzer-Profile anzeigen
 
Jan S
Moderator

Moderator


Beiträge: 10.481
Anmeldedatum: 08.07.10
Wohnort: Heidelberg
Version: 2009a, 2016b
     Beitrag Verfasst am: 23.10.2017, 02:08     Titel: Re: Figure plot automatisiert
  Antworten mit Zitat      
Hallo Henrik123,

Die Frage ist noch nicht klar.
Bei mir läuft der Code durch. Die Warnung von legend kommt daher, dass das Diagramm nur eine Kurve enthält, "list" aber mehr Namen.

Zitat:
Leider übernimmt er die Werte für die Kurven nicht.

Wer ist "er" und welche Werte werden für welche Kurven nicht übernommen?

Gruß, Jan
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
.


goMatlab ist ein Teil des goForen-Labels
goForen.de goMATLAB.de goLaTeX.de goPCB.de


 Impressum  | Nutzungsbedingungen  | Datenschutz  | Werbung/Mediadaten | Studentenversion | FAQ | goMatlab RSS Button RSS


Copyright © 2007 - 2017 goMatlab.de | Dies ist keine offizielle Website der Firma The Mathworks
Partner: LabVIEWforum.de

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.