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

label Funktion klappt nicht

 

Henrik123
Forum-Fortgeschrittener

Forum-Fortgeschrittener


Beiträge: 87
Anmeldedatum: 25.01.17
Wohnort: ---
Version: 2011a, 2017a
     Beitrag Verfasst am: 09.10.2017, 21:49     Titel: label Funktion klappt nicht
  Antworten mit Zitat      
Hallo, ich verwende folgendes Skript zum auslesen meiner Universaldatein.

Code:
%%{
%% User input
clear,clc
close all
% Input filenames
inname = {'data\400.unv', 'data\600.unv', 'data\1000.unv'};
% Number of data sets
ndata = length(inname);
B = cell(ndata,1);
iVibD=8; %index Vib - Distance/Weg
iVibV=9; %index Vib - Velocity/Geschwindigkeit
iRef1A=16; %index Ref1 - Acceleration/Beschleunigung
discriminator = 160; %Grenzwert für die Korrektur der Phasensprung
dBM=350;

%Start parameter fit
a0 = zeros(ndata,3);
a0(1,:)=[6,0.2,5];
a0(2,:)=[7,0.03,5];
a0(3,:)=[27,30,5];

a=a0

tonotopy=zeros(ndata,2)

%% Load data


for ii = 1:ndata
    % Read data
    inname{ii}
    A = readuff(inname{ii});
    length(A{1,3}.nodeN)
end

% Load scan point location info
load .\Scanpoints_Auswertung\scanloc_1000.mat; %Variable: scanloc

% For each data set
for ii = 1:ndata
    % Read data
    inname{ii}
    A = readuff(inname{ii});
    scanpoints=A{1,3}.nodeN;
    length(scanpoints)
    iv = 0;
    for iii = 1:length(scanpoints) %first we check which measurementpoints are located on the membrane
        indscanloc=find(scanloc(:,1)==scanpoints(iii),1,'first');
        if scanloc(indscanloc,3)==0 %&& ~(scanloc(indscanloc,1)==9 || scanloc(indscanloc,1)==20 || scanloc(indscanloc,1)==21 || scanloc(indscanloc,1)==22 || scanloc(indscanloc,1)==23 || scanloc(indscanloc,1)==52) && ~(scanloc(indscanloc,1)==4) %für jeden Messpunkt bestimmen ob der auf dem Membran liegt und welche Position er hat.
            iv=iv+1;
            scanlocBM(iv,1)=iii; %index in the data-file
            scanlocBM(iv,2)=scanloc(indscanloc,1); %node number
            scanlocBM(iv,3)=scanloc(indscanloc,2); %distance of the measurementpoint from the RW
        end
    end
   
    Vib = zeros(length(scanlocBM),8); %Initialize output
    Vib(:,1) = scanlocBM(:,2); %Node Number
    Vib(:,2) = scanlocBM(:,3); %Position
    for v = 1:length(scanlocBM)
        Vib(v,3) = (0.983/1.333)*abs(A{1,iVibD}.r3(scanlocBM(v,1))); %Vib: LDV - Distance/Weg corrected for the optical density difference (nair/nwater(@589 nm)=0.983/1.333)
        Vib(v,4) = angle(A{1,iVibD}.r3(scanlocBM(v,1)))*360/(2*pi); %Vib: LDV - Distance/Weg
        Vib(v,5) = 0; %Reserved for the phase-dependent amplitude
        Vib(v,6) = (0.983/1.333)*abs(A{1,iVibV}.r3(scanlocBM(v,1))); %Vib: LDV - Velocity/Geschwindigkeit corrected for the optical density difference (nair/nwater(@589 nm)=0.983/1.333)
        Vib(v,7) = angle(A{1,iVibV}.r3(scanlocBM(v,1)))*360/(2*pi); %Vib: LDV - Velocity/Geschwindigkeit
        Vib(v,8) = 0; %Reserved for the phase-dependent amplitude
    end
   
    freq(ii) = A{1,iVibD}.modeFreq;
    k = strfind(A{1,iVibD}.d1, ':');
    label_freq{ii} = A{1,iVibD}.d1(k+2:end);
    %label_freq{ii} = [num2str(freq(ii) ' Hz'];
   
    [cd indexd] = max(Vib(:,3)); %maximale Amplitude Weg gesucht
    theta0d = Vib(indexd,4);     % Phase
    [cv indexv] = max(Vib(:,6)); % maximale Amplitude Beschleunigung
    theta0v = Vib(indexv,7);
   
    for vi = 1:length(scanlocBM)
        Vib(vi,5)=Vib(vi,3)*cosd(Vib(vi,4)-theta0d);
        Vib(vi,8)=Vib(vi,6)*cosd(Vib(vi,7)-theta0v);
    end
   
    Vib = sortrows(Vib,2); %sorts the rows of Vib in ascending order of the second column (distance from the RW)
   
    %'Compensating' for the 'phasejump':
    phasejump = 0;
    for vi = 1:length(scanlocBM)
        Vib(vi,4)=Vib(vi,4)+phasejump;
        if vi<length(scanlocBM)
            %if Vib(vi,4)<(-70+phasejump) && Vib(vi+1,4)>(70+phasejump)
            if Vib(vi+1,4)>(Vib(vi,4)-phasejump+discriminator) %discriminator for the phasejump is set at 100 degrees.
                phasejump=phasejump-360;
            end
        end
    end
   
   
    %'Compensating' for the 'phasejump':
    phasejump = 0;
    for vi = 1:length(scanlocBM)
        Vib(vi,7)=Vib(vi,7)+phasejump;
        if vi<length(scanlocBM)
            %if Vib(vi,4)<(-70+phasejump) && Vib(vi+1,4)>(70+phasejump)
            if Vib(vi+1,7)>(Vib(vi,7)-phasejump+discriminator) %discriminator for the phasejump is set at 100 degrees.
                phasejump=phasejump-360;
            end
        end
    end
    %%{
  % Grouping (maximum 3) and take the median of those points. The discriminator is the distance between the points (here: < 0.2 mm)    
    iii=1;
    j=1
    while iii <= length(Vib)
      p = 1;
      if ((iii+1)<=length(Vib))
          if (abs(Vib(iii,2)-Vib(iii+1,2))<0.0002)
              p=p+1;
          end
      end
      if ((iii+2)<=length(Vib))
          if (abs(Vib(iii,2)-Vib(iii+1,2))<0.0002)&&(abs(Vib(iii+1,2)-Vib(iii+2,2))<0.0002)
              p=p+1;
          end
      end
      medarray(j,1)=0;
      medarray(j,2)=median (Vib(iii:iii+p-1,2));
      medarray(j,3)=median (Vib(iii:iii+p-1,3));
      medarray(j,4)=median (Vib(iii:iii+p-1,4));
      medarray(j,5)=median (Vib(iii:iii+p-1,5));
      medarray(j,6)=median (Vib(iii:iii+p-1,6));
      medarray(j,7)=median (Vib(iii:iii+p-1,7));
      medarray(j,8)=median (Vib(iii:iii+p-1,8));
      j=j+1;
      iii=iii+p;
    end
   %%}
   
    % fit parameters, function and fitting procedure
    xdata = 1e3*medarray(:,2)';
    ydata = 1e9*medarray(:,3)';
    fun = @(a,x) a(2).*exp(-(x-a(1)).^2/(2*a(3).^2)); %Gaussian-Function (not normalized!)
    %fun = @(a,x) (a(2)*(x-a(1))+a(3)*(x-a(1)).^2+a(4)*(x-a(1)).^3+a(5)*(x-a(1)).^4+a(6)*(x-a(1)).^5+a(7)*(x-a(1)).^6); %6th order polynome
    a(ii,:) = lsqcurvefit(fun,a0(ii,:),xdata,ydata);
    times = linspace(xdata(1),xdata(end),100);
    tonotopy(ii,1)=a(ii,1);
    tonotopy(ii,2)=freq(ii);
   
   
   
    %%{
    %--- Deutsch Envelop map with phase for overview ---%
    %OpenFig([19 6.1],'latex');
    OpenFig([28 9],'latex');
    hold all
    set(gcf,'DefaultLineLineWidth',1.0);
    set(gca, 'LineStyleOrder', {'-', '-.', '--', ':'});
    grey=[0.6,0.6,0.6];
    for i=1:2
        ax = subplot(1,2,i);
        grey=[0.6,0.6,0.6];
        greylabel=[1,1,1];
       
        if i==1
            [ax,hLine1,hLine2] = plotyy(1e3*medarray(:,2),1e9*medarray(:,3),1e3*medarray(:,2),medarray(:,4)/180);
            set(ax,'NextPlot','add')
            h1(1)=plot(ax(1),1e3*medarray(:,2),1e9*medarray(:,3),'k')
            list1{1}='Amplitude';
            h1(3)=plot(ax(1),times,fun(a(ii,:),times),'Color', [0 0.5 0])
            list1{3}='Fit';
            h1(2)=plot(ax(2),1e3*medarray(:,2),medarray(:,4)/180,'r')
            list1{2}='Phase';
            xlim(ax(1),[0 140])
            xlim(ax(2),[0 140])
            %ylim(ax(1),[0 30])
            %ylim(ax(2),[-6 6])
            set(ax(2),'xticklabel',[],'xtick',[])
            set(hLine1,'color','k')
            set(hLine2,'color','r')
            set(ax(1),'YColor','k');
            set(ax(2),'YColor','r');
            NumTicksX = 8;
            LX1 = get(ax(1),'XLim');
            LX2 = get(ax(2),'XLim');
            set(ax(1),'XTick',linspace(LX1(1),LX1(2),NumTicksX));
            set(ax(2),'XTick',linspace(LX2(1),LX2(2),NumTicksX));
            %NumTicksY = 7;
            LY1 = get(ax(1),'YLim');
            %LY2 = get(ax(2),'YLim');
            %set(ax(1),'YTick',linspace(LY1(1),LY1(2),NumTicksY));
            %set(ax(2),'YTick',linspace(LY2(1),LY2(2),NumTicksY));
            n=get(gca,'xtick');
            set(gca,'xticklabel',sprintf('%0.0f|', n));
            %line([3 3], [LY1(1) LY1(2)], 'Color',grey);
            %line([34.9 34.9], [LY1(1) LY1(2)], 'Color',grey);
            py_text=(LY1(2)-LY1(1))*0.90+LY1(1);            
        else
            hold all
            c={[0 0 1] [0 1 0] [1 0 1] [1 0.5 0]};
            %c = colormap(hot(10));
            %h=plot(1e3*Vib(:,2),1e9*Vib(:,3).*cosd(Vib(:,4)+0),'b',1e3*Vib(:,2),1e9*Vib(:,3).*cosd(Vib(:,4)+60),'g',1e3*Vib(:,2),1e9*Vib(:,3).*cosd(Vib(:,4)+120),'m',1e3*Vib(:,2),1e9*Vib(:,3).*cosd(Vib(:,4)+180),'k');
            h2(1)=plot(1e3*medarray(:,2),1e9*medarray(:,3).*cosd(medarray(:,4)+0), 'Color', c{1});
            list2{1} = '0$^\circ$';
            h2(2)=plot(1e3*medarray(:,2),1e9*medarray(:,3).*cosd(medarray(:,4)+60),'Color', c{2});
            list2{2} = '60$^\circ$';
            h2(3)=plot(1e3*medarray(:,2),1e9*medarray(:,3).*cosd(medarray(:,4)+120),'Color', c{3});
            list2{3} = '120$^\circ$';
            h2(4)=plot(1e3*medarray(:,2),1e9*medarray(:,3).*cosd(medarray(:,4)+180),'Color', c{4});
            list2{4} = '180$^\circ$';
            xlim([0 140])
            ylim([-LY1(2) LY1(2)])
            %line([3 3], [-LY1(2) LY1(2)], 'Color',grey);
            %line([34.9 34.9], [-LY1(2) LY1(2)], 'Color',grey);
            NumTicksX = 8;
            LX = get(gca,'XLim');
            set(gca,'XTick',linspace(LX(1),LX(2),NumTicksX));
            %NumTicksY = 7;
            LY = get(gca,'YLim')
            %set(gca,'YTick',linspace(LY(1),LY(2),NumTicksY));
            n=get(gca,'xtick');
            set(gca,'xticklabel',sprintf('%0.0f|', n));
            py_text=(LY(2)-LY(1))*0.90+LY(1);
            %
            xlimtxt=get(gca,'XLim');
            xlimtxt=get(gca,'XLim');
            ylimtxt=get(gca,'YLim');
            if freq(ii) >= 1000
                text(xlimtxt(2)+1,ylimtxt(2),{['$f = $ ' num2str(floor(freq(ii)/1000)) ' ' label_freq{ii}(length(num2str(floor(freq(ii)/1000)))+1:end-2) ' Hz'];['$d_{BM} =$ ' num2str(dBM) ' ${\mathrm{\mu m}}$']}, 'VerticalAlignment','top', 'FontSize',12,'BackgroundColor',greylabel,'FontWeight','bold','EdgeColor',greylabel,'LineWidth',0.5)
            else
                text(xlimtxt(2)+1,ylimtxt(2),{['$f = $ ' num2str(freq(ii)) ' Hz'];['$d_{BM} =$ ' num2str(dBM) ' ${\mathrm{\mu m}}$']}, 'VerticalAlignment','top', 'FontSize',12,'BackgroundColor',greylabel,'FontWeight','bold','EdgeColor',greylabel,'LineWidth',0.5)
            end
            %text(xlimtxt(2)+2,py_text,[num2str(mean(A{1,iRef1A}.r3),'%.2f') ' $\mathrm{m/s^2}$ (' num2str(1e9*mean(A{1,iRef1A}.r3)/(2*pi*freq(ii))^2,'%.0f') ' $\mathrm{nm}$)'],'VerticalAlignment','bottom','HorizontalAlignment','left','FontSize',8)
        end
        grid on
        box on
        %text(30,py_text,[label_freq{ii}],'FontSize',10,'BackgroundColor',greylabel,'FontWeight','bold','EdgeColor',greylabel,'LineWidth',0.5)
        %p_width=6;
        p_width=9;
        %p_height=4.5;
        p_height=7.5;
        p_left=3.5;
        %p_right=10;
        p_right=15.5;
        p_bottom=1.4;
        p={[p_left p_bottom p_width p_height] [p_right p_bottom p_width p_height]};
        set(gca, 'position', p{i});
        if i==1
            xlabel(ax(1),'Distanz vom RW in ${\mathrm{mm}}$','FontSize',10)
            ylabel(ax(1),'Amplitude in $\mathrm{nm}$','FontSize',10)
            ylabel(ax(2),'Phase in $\mathrm{\Pi}$','FontSize',16)
            %legend({'Amplitude' 'Fit' 'Phase'},'Position',[24 6 2.0 0.5])
            legend(h1,list1,'Position',[24 6 2.0 0.5])
            legend('boxoff')
        else
            xlabel('Distanz vom RW in ${\mathrm{mm}}$','FontSize',10)
            ylabel('Auslenkung in $\mathrm{nm}$','FontSize',10)
            %legend(h,{'0\circ' '60\circ' '120\circ' '180\circ'},'Position',[26 4 1.0 2],'FontSize',8)
            legend(h2,list2,'Position',[24 2.5 1.0 2])
            legend('boxoff')
        end
    FormatFigXtitle_paper(-1.5,-2,0.4,-0.2);        
    end
    PlotFig(['BM Schwingung und Phase bei ' label_freq{ii} ' (' inname{ii}(6:end-4) ')']);
    %%}
   
    clearvars scanlocBM %Since this variable is not initialized / cleared after each sequence

    B{ii,1}.ID = label_freq{ii}; %each dataset get its unique flag
    B{ii,1}.data = Vib; %the corresponding data

end

matfilename = ['tonotopy_' num2str(dBM) 'um.mat'];
save(matfilename, 'tonotopy');

C = [tonotopy(:,1), tonotopy(:,2)];
filename = ['tonotopy_' num2str(dBM) 'um.txt'];
save(filename, 'C', '-ascii');
 


Leider ist der Befehlt plotyy nicht mehr gültig. Das Skript ist aus der Version von 2011 und in der Version 2017 nicht mehr zu verwenden. Hat jemand eine Idee wie ich vom Befehl plotyy zu yyaxis konvertiere? Das Problem beginnt ab Zeile 164 mit dem Start von plotyy.

Habe die zip-Datei im Anhang hinterlegt.

161101_TestRig_FastScan.zip
 Beschreibung:

Download
 Dateiname:  161101_TestRig_FastScan.zip
 Dateigröße:  927.45 KB
 Heruntergeladen:  359 mal
Private Nachricht senden Benutzer-Profile anzeigen


Jan S
Moderator

Moderator


Beiträge: 11.057
Anmeldedatum: 08.07.10
Wohnort: Heidelberg
Version: 2009a, 2016b
     Beitrag Verfasst am: 10.10.2017, 15:16     Titel: Re: label Funktion klappt nicht
  Antworten mit Zitat      
Hallo Henrik123,

Es ist weniger abschreckend, wenn Du nur den relevanten Teil des Codes postest.

Code:
% [ax,hLine1,hLine2] = plotyy(1e3*medarray(:,2),1e9*medarray(:,3),1e3*medarray(:,2),medarray(:,4)/180);
yyaxis left
hLine1 = plot(1e3*medarray(:,2), 1e9*medarray(:,3));
hold on
h1(1)=plot(,1e3*medarray(:,2),1e9*medarray(:,3),'k')
list1{1}='Amplitude';
h1(3)=plot(,times,fun(a(ii,:),times),'Color', [0 0.5 0])
list1{3}='Fit';

yyaxis right
hLine2 = plot(1e3*medarray(:,2),medarray(:,4)/180);
hold on
h1(2)   = plot(1e3*medarray(:,2),medarray(:,4)/180,'r')
 

Wird die Idee klar?

Gruß, Jan
Private Nachricht senden Benutzer-Profile anzeigen
 
Henrik123
Themenstarter

Forum-Fortgeschrittener

Forum-Fortgeschrittener


Beiträge: 87
Anmeldedatum: 25.01.17
Wohnort: ---
Version: 2011a, 2017a
     Beitrag Verfasst am: 10.10.2017, 16:08     Titel:
  Antworten mit Zitat      
Die Parameter ax(i) hast du aus dem Code genommen. Wie solle ich dann meine Formatierung indizieren?

Funktioniert Xticklabel dann noch? Habe die Erfahrung gemacht, dass er die x-Achse zweimal übereinander schreibt.
Private Nachricht senden Benutzer-Profile anzeigen
 
Harald
Forum-Meister

Forum-Meister


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

ich würde nicht sagen, dass plotyy nicht mehr gültig ist, sondern es ist (für neu entwickelten) Code nicht empfohlen.

Zitat:
Das Skript ist aus der Version von 2011 und in der Version 2017 nicht mehr zu verwenden.

Und das schließt du woraus? Bekommst du eine Fehlermeldung? Welche?
Auch der Titel des Threads ist hier wenig aussagekräftig.

Zitat:
Wie solle ich dann meine Formatierung indizieren?

Wenn ich die Frage richtig verstehe: die Formatierung direkt erledigen, wenn man in einem der Koordinatensysteme arbeitet, oder später nochmal mit yyaxis left und yyaxis right hin- und herwechseln.

Zitat:
Funktioniert Xticklabel dann noch?

Warum sollte es nicht funktionieren?

Grüße,
Harald

P.S.: Es ist ja nicht deine erste Frage... prinzipiell: je klarer die Frage, desto leichter und besser kann man antworten.
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.