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

Definieren von Coefs!

 

kaylou

Gast


Beiträge: ---
Anmeldedatum: ---
Wohnort: ---
Version: ---
     Beitrag Verfasst am: 24.11.2017, 18:54     Titel: Definieren von Coefs!
  Antworten mit Zitat      
Ich habe folgenden Code programmiert:
clear all,close all,clc
% Ratte 2
a=[1.1787 1.3332 1.3332 1.3591 1.3134 1.3269 1.4333 1.3652 -2.2208 -2.1731 -2.2156 2.1440 -2.2064 2.1231]; %Werte log(RWDl/RWDr)
b=[0.6490 0.8972 0.9956 1.0351 1.2701 0.9820 0.9698 0.9572 -1.1926 -1.4404 -1.7277 0.7095 -1.5511 1.0228]; %Werte log(tl/tr)

%Ratte 1
c=[-1.0986 -1.4053 -1.4367 -1.3196 -1.4118 -1.5210 -1.4404 -1.4718 -2.2588 -2.2588 -2.2809 2.2051 -2.1440 2.1595] %Werte log(RWDl/RWDr)
d=[-1.3437 -0.9876 -0.8786 -0.8007 -1.1501 -1.3055 -1.2881 -1.2693 -1.4940 -1.9104 -1.5450 0.6982 -1.2170 0.8549] %werte log(tl/tr)



x=[-3,3];
y=[0,0];
x_1=[0,0];
y_1=[-3,3];

xlim([-3 3])
% xticks([-3 -2 -1 0 1])
ylim([-3 1])
% yticks([-2.5 -2 -1 0 1])


z=[ -3 -2 -1 0 1 2 3]; %x-Werte ideale Gerade
v=[ -3 -2 -1 0 1 2 3]; %y-Werte ideale Gerade


figure,hold on
colors = get(gca,'ColorOrder');
xvals = -3:3;
plot(a,b,'o','Color',colors(1,Smile) %RATTE 2
coefs = polyfit(a,b,1);
yvals = coefs(1)*xvals+coefs(2);
plot(xvals,yvals,'Color',colors(1,Smile)
disp(['Coefficients 1: ',num2str(coefs)])


plot(z,v,'-','Color',colors(2,Smile)
coefs = polyfit(z,v,1);
yvals = coefs(1)*xvals+coefs(2);
plot(xvals,yvals,'Color',colors(2,Smile)
disp(['Coefficients 2: ',num2str(coefs)])

plot(c,d,'o','Color',colors(3,Smile) %Ratte 1
coefs = polyfit(c,d,1);
yvals = coefs(1)*xvals+coefs(2);
plot(xvals,yvals,'Color',colors(3,Smile)
disp(['Coefficients 3:',num2str(coefs)])


text(-2.8,2.8,['Ratte 2 blue: a=',num2str(coefs(1),'%2.2f'),',b=',num2str(coefs(2),'%2.2f')])

text(-2.8 ,2.5,['Ratte 1 yellow: c=',num2str(coefs(1),'%2.2f'),',d=',num2str(coefs(2),'%2.2f')])


p=plot(x,y,'--');
p1=plot(x_1,y_1,'--');
set([p,p1],'Color',[0.7 0.7 0.7],'Linewidth',0.5)

xlabel('log(Rf_1/(Rf_2))') %Achsenname x
ylabel('log(t_1/t_2)') %Achsenname y
savefig('MatchingGeradeR1&2')



Mein Problem:
Die Werte auf folgender Zeile werden immer überschrieben:
text(-2.8,2.8,['Ratte 2 blue: a=',num2str(coefs(1),'%2.2f'),',b=',num2str(coefs(2),'%2.2f')])

text(-2.8 ,2.5,['Ratte 1 yellow: c=',num2str(coefs(1),'%2.2f'),',d=',num2str(coefs(2),'%2.2f')])



und obwohl er die richtigen Werte im Programm ausgibt, schreibt er immer wieder die falschen in die figure. Hat jemand eine Idee wie ich die Coefs abgrenzen kann oder das Überschreiben unterdrücken kann? Hold on oder hold all funktioniert leider nicht, weil die coefs ja die gleichen sind.
Ich stehe gerade echt auf dem Schlauch..


Maluco
Forum-Newbie

Forum-Newbie


Beiträge: 9
Anmeldedatum: 27.06.17
Wohnort: ---
Version: R2017b
     Beitrag Verfasst am: 25.11.2017, 15:20     Titel:
  Antworten mit Zitat      
Hey kaylou!

Wenn du die Variable überschreibst, hast du keinen Zugriff mehr auf diese Werte, außer du speicherst sie unter einem anderen Namen ab. Ich gehe aber mal davon aus, dass dein Problem ist, dass du die richtigen Werte im Plot angezeigt haben willst und dir das Speichern der Werte nicht so wichtig ist. Platziere die text-Befehle einfach bei den dazugehörigen Plots und es gibt kein Problem mit der Darstellung. Damit wird zwar die Variable überschrieben, aber du hast die richtigen Werte im Plot.

Code:
clear all,close all,clc
% Ratte 2
a=[1.1787 1.3332 1.3332 1.3591 1.3134 1.3269 1.4333 1.3652 -2.2208 -2.1731 -2.2156 2.1440 -2.2064 2.1231]; %Werte log(RWDl/RWDr)
b=[0.6490 0.8972 0.9956 1.0351 1.2701 0.9820 0.9698 0.9572 -1.1926 -1.4404 -1.7277 0.7095 -1.5511 1.0228]; %Werte log(tl/tr)

%Ratte 1
c=[-1.0986 -1.4053 -1.4367 -1.3196 -1.4118 -1.5210 -1.4404 -1.4718 -2.2588 -2.2588 -2.2809 2.2051 -2.1440 2.1595] %Werte log(RWDl/RWDr)
d=[-1.3437 -0.9876 -0.8786 -0.8007 -1.1501 -1.3055 -1.2881 -1.2693 -1.4940 -1.9104 -1.5450 0.6982 -1.2170 0.8549] %werte log(tl/tr)



x=[-3,3];
y=[0,0];
x_1=[0,0];
y_1=[-3,3];

xlim([-3 3])
% xticks([-3 -2 -1 0 1])
ylim([-3 1])
% yticks([-2.5 -2 -1 0 1])


z=[ -3 -2 -1 0 1 2 3]; %x-Werte ideale Gerade
v=[ -3 -2 -1 0 1 2 3]; %y-Werte ideale Gerade


figure(1), clf, hold on
colors = get(gca,'ColorOrder');
xvals = -3:3;
plot(a,b,'o','Color',colors(1,:)) %RATTE 2
coefs = polyfit(a,b,1)
yvals = coefs(1)*xvals+coefs(2);
plot(xvals,yvals,'Color',colors(1,:))
disp(['Coefficients 1: ',num2str(coefs)])

text(-2.8,2.8,['Ratte 2 blue: a=',num2str(coefs(1),'%2.2f'),',b=',num2str(coefs(2),'%2.2f')])


plot(z,v,'-','Color',colors(2,:))
coefs = polyfit(z,v,1)
yvals = coefs(1)*xvals+coefs(2);
plot(xvals,yvals,'Color',colors(2,:))
disp(['Coefficients 2: ',num2str(coefs)])

plot(c,d,'o','Color',colors(3,:)) %Ratte 1
coefs = polyfit(c,d,1)
yvals = coefs(1)*xvals+coefs(2);
plot(xvals,yvals,'Color',colors(3,:))
disp(['Coefficients 3:',num2str(coefs)])

text(-2.8 ,2.5,['Ratte 1 yellow: c=',num2str(coefs(1),'%2.2f'),',d=',num2str(coefs(2),'%2.2f')])


p=plot(x,y,'--');
p1=plot(x_1,y_1,'--');
set([p,p1],'Color',[0.7 0.7 0.7],'Linewidth',0.5)

xlabel('log(Rf_1/(Rf_2))') %Achsenname x
ylabel('log(t_1/t_2)') %Achsenname y
savefig('MatchingGeradeR1&2')
 
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 - 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.