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 -1200],[0 L -11];
[0 L -10020], [0 L -51];
[0 L -4080], [0 L -51];
[0 L -10020],[0 L -51];
};
%% 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
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 (line674)
In legend>make_legend (line346)
In legend(line294)
In english (line156) Warning: Ignoring extra legend entries.
> In legend>set_children_and_strings (line674)
In legend>make_legend (line346)
In legend(line294)
In english (line156) Warning: Ignoring extra legend entries.
> In legend>set_children_and_strings (line674)
In legend>make_legend (line346)
In legend(line294)
In english (line156) Warning: Ignoring extra legend entries.
> In legend>set_children_and_strings (line674)
In legend>make_legend (line346)
In legend(line294)
In english (line156) Warning: Ignoring extra legend entries.
> In legend>set_children_and_strings (line674)
In legend>make_legend (line346)
In legend(line294)
In english (line156) Warning: Ignoring extra legend entries.
> In legend>set_children_and_strings (line674)
In legend>make_legend (line346)
In legend(line294)
In english (line156) Warning: Ignoring extra legend entries.
> In legend>set_children_and_strings (line674)
In legend>make_legend (line346)
In legend(line294)
In english (line156) Warning: Ignoring extra legend entries.
> In legend>set_children_and_strings (line674)
In legend>make_legend (line346)
In legend(line294)
In english (line156) Warning: Ignoring extra legend entries.
> In legend>set_children_and_strings (line674)
In legend>make_legend (line346)
In legend(line294)
In english (line156) Warning: Ignoring extra legend entries.
> In legend>set_children_and_strings (line674)
In legend>make_legend (line346)
In legend(line294)
In english (line156) Warning: Ignoring extra legend entries.
> In legend>set_children_and_strings (line674)
In legend>make_legend (line346)
In legend(line294)
In english (line156) Warning: Ignoring extra legend entries.
> In legend>set_children_and_strings (line674)
In legend>make_legend (line346)
In legend(line294)
In english (line156) Warning: Ignoring extra legend entries.
> In legend>set_children_and_strings (line674)
In legend>make_legend (line346)
In legend(line294)
In english (line156) Warning: Ignoring extra legend entries.
> In legend>set_children_and_strings (line674)
In legend>make_legend (line346)
In legend(line294)
In english (line156) Warning: Ignoring extra legend entries.
> In legend>set_children_and_strings (line674)
In legend>make_legend (line346)
In legend(line294)
In english (line156) Warning: Ignoring extra legend entries.
> In legend>set_children_and_strings (line674)
In legend>make_legend (line346)
In legend(line294)
In english (line156) Warning: Ignoring extra legend entries.
> In legend>set_children_and_strings (line674)
In legend>make_legend (line346)
In legend(line294)
In english (line156) Warning: Ignoring extra legend entries.
> In legend>set_children_and_strings (line674)
In legend>make_legend (line346)
In legend(line294)
In english (line156) Warning: Ignoring extra legend entries.
> In legend>set_children_and_strings (line674)
In legend>make_legend (line346)
In legend(line294)
In english (line156) Warning: Ignoring extra legend entries.
> In legend>set_children_and_strings (line674)
In legend>make_legend (line346)
In legend(line294)
In english (line156)
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
Einstellungen und Berechtigungen
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
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.