[WIP] Breaking Change - Use Update

Folder name is changed, rework the html templates
Change the organisation.
This commit is contained in:
2019-05-10 16:06:43 +02:00
parent 8d8c03773c
commit 6e3677eb29
162 changed files with 3800 additions and 582492 deletions

View File

@@ -0,0 +1,152 @@
function [Res] = Dual_Spindle_error(dataX, dataY, NbTurn,texte, path)
L= length(dataX);
res_per_rev = L/NbTurn;
P = 0: (res_per_rev * NbTurn)-1;
Pos = P' * 360/res_per_rev;
Theta = degtorad(Pos)';
x1 = myfit2(Pos, dataX);
y1 = myfit2(Pos, dataY);
%Convert data to frequency domain and scale accordingly
X2 = 2/(res_per_rev*NbTurn)*fft(x1);
f2 = (0:L-1)./NbTurn;
Y2 = 2/(res_per_rev*NbTurn)*fft(y1);
% Separate the fft integers and not-integers
for i = 1 : length(f2)
if mod(f2(i), 1) == 0;
X2dec(i)= 0;
X2int(i)= X2(i);
Y2dec(i)= 0;
Y2int(i)= Y2(i);
else
X2dec(i)= X2(i);
X2int(i)= 0;
Y2dec(i)= Y2(i);
Y2int(i)= 0;
end
end
if mod(length(f2),2) ==1; % Case length(f2) is odd -> the mirror image of the FFT is reflected between 2 harmonique
for i = length(f2)/2 +1.5: length(f2)
if mod(f2(i-1), 1) == 0;
X2dec(i)= 0;
X2int(i)= X2(i);
Y2dec(i)= 0;
Y2int(i)= Y2(i);
else
X2dec(i)= X2(i);
X2int(i)= 0;
Y2dec(i)= Y2(i);
Y2int(i)= 0;
end
end
else % Case length(f2) is even -> the mirror image of the FFT is reflected at the Nyquist frequency
for i = length(f2)/2 +1: length(f2)
if mod(f2(i), 1) == 0;
X2dec(i)= 0;
X2int(i)= X2(i);
Y2dec(i)= 0;
Y2int(i)= Y2(i);
else
X2dec(i)= X2(i);
X2int(i)= 0;
Y2dec(i)= Y2(i);
Y2int(i)= 0;
end
end
end
X2int(1) = 0; %remove the data average/dc component
X2int(NbTurn+1) = 0; %Remove fondamental/eccentricity
% X2int(length(f2)) = 0; %remove the data average/dc component
X2int(length(f2)-NbTurn+1) = 0; %Remove eccentricity
Y2int(1) = 0; %remove the data average/dc component
Y2int(NbTurn+1) = 0; %Remove fondamental/eccentricity
% Y2int(length(f2)) = 0; %remove the data average/dc component
Y2int(length(f2)-NbTurn+1) = 0; %Remove eccentricity
% Extract the fondamentale-> exentricity
for i = 1:length(f2)
if i == NbTurn+1 || i== length(f2)-NbTurn + 1
X2fond(i) = X2(i);
Y2fond(i) = Y2(i);
else
X2fond(i) = 0;
Y2fond(i) = 0;
end
end
X2tot= X2int + X2dec;
Y2tot= Y2int + Y2dec;
%Convert data to "time" domain and scale accordingly
Wxint = real((res_per_rev*NbTurn)/2 * ifft(X2int)) ;
Wxdec = real((res_per_rev*NbTurn)/2 * ifft(X2dec)) ;
Wxtot = real((res_per_rev*NbTurn)/2 * ifft(X2tot)) ;
%Convert data to "time" domain and scale accordingly
Wyint = real((res_per_rev*NbTurn)/2 * ifft(Y2int)) ;
Wydec = real((res_per_rev*NbTurn)/2 * ifft(Y2dec)) ;
Wytot = real((res_per_rev*NbTurn)/2 * ifft(Y2tot)) ;
%%
fig = figure();
% subplot(3, 2, 5); bar(f2(1:50*NbTurn),abs(W2int(1:50*NbTurn)),3) ;
% axis([0,50,0,max(abs(X2int(1:50*NbTurn)))]);
% title ('Fourier integer' ); xlabel('UPR'); ylabel ('Microns')
% subplot(3, 2, 6); bar(f2(1:50*NbTurn),abs(W2dec(1:50*NbTurn)),2); title (' Fourier non-integer' );
% axis([0,50,0,max(abs(X2dec(1:50*NbTurn)))]);
% title ('Fourier non-integer' ); xlabel('UPR'); ylabel ('Microns')
% Sensitive pos dir (synchrone+asynchrone)
Wtot= Wytot.*cos(Theta)+Wxtot.*sin(Theta);
% Wtot= Wytot+Wxtot; = WTot = real((res_per_rev*NbTurn)/2 * ifft(W2tot)) ;
%Sensitive pos dir (synchrone+asynchrone)
Wint= Wyint.*cos(Theta)+Wxint.*sin(Theta);
%Sensitive pos dir (synchrone+asynchrone)
Wdec= Wydec.*cos(Theta)+Wxdec.*sin(Theta);
% total error motion
Total_Error = max(Wtot)- min(Wtot);
%lsc X synchronous
Synchronous_Error = max(Wint)- min(Wint);
%lsc X Asynchronous
var=reshape(Wxdec,length(Wxdec)/NbTurn,NbTurn);
for i=1:length(Wxdec)/NbTurn
Asynch(i) = max(var(i,:)) - min(var(i,:)) ;
end
Asynchronous_Error = max(Asynch)- min(Asynch);
% Raw Error Motion without Exentricity (sync +asynch)
subplot(2, 2, 2) ; polar2(Theta,Wtot, 'b'); title (' Total error' );
% Residual Synchronous Error Motion without Exentricity (ie fondamental sync err motion)
subplot(2, 2, 3) ;polar2(Theta,Wint,'b'); title ( 'Residual synchronous error' );
% Asynchronous Error Motion
subplot(2, 2, 4) ;polar2(Theta,Wdec, 'b'); title ('Asynchronous error' );
strmin1 = ['Total error = ', num2str(Total_Error*1000), ' nm'];
strmin2 = ['Residual synchronous error = ', num2str(Synchronous_Error*1000), ' nm' ];
strmin3 = ['Asynchronous error = ', num2str(Asynchronous_Error*1000), ' nm'];
dim0=[0.04 0.5 0.3 .3];%x y w h basgauche to hautdroite
dim1=[0.15 0.65 0.3 .3];
annotation('textbox',dim0, 'String',{ strmin1 , strmin2, strmin3}, 'FitBoxToText', 'on')
annotation('textbox',dim1, 'String',texte, 'FitBoxToText', 'on')
saveas(fig,fullfile(path,char(texte)),'jpg');
Res=1;
close all;
end

Binary file not shown.

After

Width:  |  Height:  |  Size: 74 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 72 KiB

View File

@@ -0,0 +1,32 @@
clear; close all; clc;
%%
datapath = './data/';
savepath = './Macros_ttt_spindle/';
name_of_the_datafile = '10turns_60rpm_IcepapFIR.txt';
NbTurn = 10; % Be careful that this value match with the measure
%%
% [y, x, z, y2, x2] = importfile(fullfile(datapath,name_of_the_datafile),12, inf);
spindle_table = readtable([datapath, name_of_the_datafile]);
data = table2array(spindle_table);
% data = [y x z y2 x2];
data = data(:, 3:end);
texte = {'Y Axis' 'X Axis' 'Z Axis' 'Y2 Axis' 'X2 Axis'};
texte2 = {'Rotating radial Error XY' 'Rotating radial Error X2Y2' 'Tilt Error XX2' 'Tilt Error YY2' };
%%
for i = 1:5
Spindle_error(data(:,i), NbTurn, texte(:,i), savepath);
end
%%
Dual_Spindle_error(data(:,2), data(:,1),NbTurn,texte2(:,1), savepath);
Dual_Spindle_error(data(:,5), data(:,4),NbTurn,texte2(:,2), savepath);
Tilt_Spindle_error(data(:,2), data(:,5),NbTurn,texte2(:,3), savepath);
Tilt_Spindle_error(data(:,1), data(:,4),NbTurn,texte2(:,4), savepath);

View File

@@ -0,0 +1,131 @@
function [Res] = Spindle_error(data, NbTurn, texte, path)
%%
L = length(data);
res_per_rev = L/NbTurn;
P = 0:(res_per_rev*NbTurn-1);
Pos = P' * 360/res_per_rev;
Theta = deg2rad(Pos)';
% Temperature correction
x1 = myfit2(Pos, data);
% Convert data to frequency domain and scale accordingly
X2 = 2/(res_per_rev*NbTurn)*fft(x1);
f2 = (0:L-1)./NbTurn; %upr -> once per revolution
%% Separate the fft integers and not-integers
for i = 1:length(f2)
if mod(f2(i), 1) == 0
X2dec(i) = 0;
X2int(i) = X2(i);
else
X2dec(i) = X2(i);
X2int(i) = 0;
end
end
%% Case length(f2) is odd -> the mirror image of the FFT is reflected between 2 harmonique
if mod(length(f2),2) == 1
for i = length(f2)/2+1.5:length(f2)
if mod(f2(i-1), 1) == 0
X2dec(i) = 0;
X2int(i) = X2(i);
else
X2dec(i) = X2(i);
X2int(i) = 0;
end
end
else % Case length(f2) is even -> the mirror image of the FFT is reflected at the Nyquist frequency
for i = length(f2)/2+1:length(f2)
if mod(f2(i), 1) == 0
X2dec(i) = 0;
X2int(i) = X2(i);
else
X2dec(i) = X2(i);
X2int(i) = 0;
end
end
end
%%
X2int(1) = 0; %remove the data average/dc component
X2int(NbTurn+1) = 0; %Remove fondamental/eccentricity
% X2int(length(f2)) = 0; %remove the data average/dc component
X2int(length(f2)-NbTurn+1) = 0; %Remove eccentricity
%% Extract the fondamental -> exentricity
for i = 1:length(f2)
if i == NbTurn+1 || i == length(f2)-NbTurn+1
X2fond(i) = X2(i);
else
X2fond(i) = 0;
end
end
X2tot = X2int + X2dec;
Wxfond = real((res_per_rev*NbTurn)/2 * ifft(X2fond)); % Convert data to "time" domain and scale accordingly
Wxint = real((res_per_rev*NbTurn)/2 * ifft(X2int));
Wxdec = real((res_per_rev*NbTurn)/2 * ifft(X2dec));
Wxtot = real((res_per_rev*NbTurn)/2 * ifft(X2tot));
%%
fig = figure();
subplot(3, 2, 5);
bar(f2(1:50*NbTurn),1000*abs(X2int(1:50*NbTurn)),3);
axis([0,50,0,1000*max(abs(X2int(1:50*NbTurn)))]);
title ('Fourier integer');
xlabel('UPR'); ylabel ('nm')
subplot(3, 2, 6);
bar(f2(1:50*NbTurn),1000*abs(X2dec(1:50*NbTurn)),2);
title('Fourier non-integer');
axis([0,50,0,1000*max(abs(X2dec(1:50*NbTurn)))]);
title('Fourier non-integer');
xlabel('UPR'); ylabel ('nm')
% Eccentricity
Eccentricity = max(Wxfond) - min(Wxfond);
% total error motion X
Total_Error = max(Wxtot) - min(Wxtot);
% lsc X synchronous
Synchronous_Error = max(Wxint) - min(Wxint);
% lsc X Asynchronous
var = reshape(Wxdec,length(Wxdec)/NbTurn,NbTurn);
for i = 1:length(Wxdec)/NbTurn
Asynch(i) = max(var(i,:)) - min(var(i,:));
end
Asynchronous_Error = max(Asynch) - min(Asynch);
% Raw Error Motion without Exentricity (sync +asynch)
subplot(3, 2, 2);
polar2(Theta,Wxtot, 'b');
title ('Total error');
% Residual Synchronous Error Motion without Exentricity (ie fondamental sync err motion)
subplot(3, 2, 3);
polar2(Theta,Wxint,'b');
title('Residual synchronous error');
% Asynchronous Error Motion
subplot(3, 2, 4);
polar2(Theta,Wxdec, 'b');
title('Asynchronous error');
strmin0 = ['Eccentricity= ', num2str(Eccentricity), ' \mum '];
strmin1 = ['Total error = ', num2str(Total_Error*1000), ' nm'];
strmin2 = ['Residual synchronous error = ', num2str(Synchronous_Error*1000), ' nm' ];
strmin3 = ['Asynchronous error = ', num2str(Asynchronous_Error*1000), ' nm'];
dim0 = [0.1 0.55 0.3 .3];%x y w h basgauche to hautdroite
dim1 = [0.15 0.65 0.3 .3];
annotation('textbox',dim0, 'String',{ strmin0 ,strmin1 , strmin2, strmin3}, 'FitBoxToText', 'on')
annotation('textbox',dim1, 'String',texte, 'FitBoxToText', 'on')
saveas(fig,fullfile(path,char(texte)),'jpg');
Res = 1;
close all;
end

Binary file not shown.

After

Width:  |  Height:  |  Size: 77 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 66 KiB

View File

@@ -0,0 +1,146 @@
function Res = Tilt_Spindle_error(dataX, dataX2,NbTurn, texte, path)
L = length(dataX);
res_per_rev = L/NbTurn;
P = 0: (res_per_rev * NbTurn)-1;
Pos = P'*360/res_per_rev;
Theta = deg2rad(Pos)';
D = 76.2; %distance entre les deux balls en milimetres
x1 = myfit2(Pos, dataX);
y1 = myfit2(Pos, dataX2);
%Convert data to frequency domain and scale accordingly
X2 = 2/(res_per_rev*NbTurn)*fft(x1);
f2 = (0:L-1)./NbTurn;
Y2 = 2/(res_per_rev*NbTurn)*fft(y1);
% Separate the fft integers and not-integers
for i = 1:length(f2)
if mod(f2(i), 1) == 0
X2dec(i) = 0;
X2int(i) = X2(i);
Y2dec(i) = 0;
Y2int(i) = Y2(i);
else
X2dec(i) = X2(i);
X2int(i) = 0;
Y2dec(i) = Y2(i);
Y2int(i) = 0;
end
end
if mod(length(f2),2) == 1 % Case length(f2) is odd -> the mirror image of the FFT is reflected between 2 harmonique
for i = length(f2)/2+1.5:length(f2)
if mod(f2(i-1), 1) == 0
X2dec(i) = 0;
X2int(i) = X2(i);
Y2dec(i) = 0;
Y2int(i) = Y2(i);
else
X2dec(i) = X2(i);
X2int(i) = 0;
Y2dec(i) = Y2(i);
Y2int(i) = 0;
end
end
else % Case length(f2) is even -> the mirror image of the FFT is reflected at the Nyquist frequency
for i = length(f2)/2+1:length(f2)
if mod(f2(i), 1) == 0;
X2dec(i) = 0;
X2int(i) = X2(i);
Y2dec(i) = 0;
Y2int(i) = Y2(i);
else
X2dec(i) = X2(i);
X2int(i) = 0;
Y2dec(i) = Y2(i);
Y2int(i) = 0;
end
end
end
X2int(1) = 0; %remove the data average/dc component
X2int(NbTurn+1) = 0; %Remove fondamental/eccentricity
% X2int(length(f2)) = 0; %remove the data average/dc component
X2int(length(f2)-NbTurn+1) = 0; %Remove eccentricity
Y2int(1) = 0; %remove the data average/dc component
Y2int(NbTurn+1) = 0; %Remove fondamental/eccentricity
% Y2int(length(f2)) = 0; %remove the data average/dc component
Y2int(length(f2)-NbTurn+1) = 0; %Remove eccentricity
% Extract the fondamentale-> exentricity
for i = 1:length(f2)
if i == NbTurn+1 || i== length(f2)-NbTurn + 1
X2fond(i) = X2(i);
Y2fond(i) = Y2(i);
else
X2fond(i) = 0;
Y2fond(i) = 0;
end
end
X2tot = X2int + X2dec;
Y2tot = Y2int + Y2dec;
%Convert data to "time" domain and scale accordingly
Wxint = real((res_per_rev*NbTurn)/2*ifft(X2int));
Wxdec = real((res_per_rev*NbTurn)/2*ifft(X2dec));
Wxtot = real((res_per_rev*NbTurn)/2*ifft(X2tot));
%Convert data to "time" domain and scale accordingly
Wyint = real((res_per_rev*NbTurn)/2*ifft(Y2int));
Wydec = real((res_per_rev*NbTurn)/2*ifft(Y2dec));
Wytot = real((res_per_rev*NbTurn)/2*ifft(Y2tot));
Tint = atan((Wyint - Wxint)/(D*1000));
Tdec = atan((Wydec - Wxdec)/(D*1000));
Ttot = atan((Wytot - Wxtot)/(D*1000));
%%
fig = figure();
% total error motion
Total_Error = max(Ttot)- min(Ttot);
%lsc X synchronous
Synchronous_Error = max(Tint)- min(Tint);
%lsc X Asynchronous
var = reshape(Tdec,length(Tdec)/NbTurn,NbTurn);
for i = 1:length(Tdec)/NbTurn
Asynch(i) = max(var(i,:)) - min(var(i,:)) ;
end
Asynchronous_Error = max(Asynch)- min(Asynch);
% Raw Error Motion without Exentricity (sync +asynch)
subplot(2, 2, 2);
polar2(Theta,Ttot, 'b');
title('Total error');
% Residual Synchronous Error Motion without Exentricity (ie fondamental sync err motion)
subplot(2, 2, 3);
polar2(Theta,Tint,'b');
title('Residual synchronous error');
% Asynchronous Error Motion
subplot(2, 2, 4);
polar2(Theta,Tdec, 'b');
title ('Asynchronous error');
%%
strmin1 = ['Total error = ', num2str(Total_Error*1000000), ' \murad'];
strmin2 = ['Residual synchronous error = ', num2str(Synchronous_Error*1000000), ' \murad' ];
strmin3 = ['Asynchronous error = ', num2str(Asynchronous_Error*1000000), ' \murad'];
dim0 =[0.04 0.5 0.3 .3];%x y w h basgauche to hautdroite
dim1 =[0.15 0.65 0.3 .3];
annotation('textbox',dim0, 'String',{ strmin1 , strmin2, strmin3}, 'FitBoxToText', 'on')
annotation('textbox',dim1, 'String',texte, 'FitBoxToText', 'on')
saveas(fig,fullfile(path,char(texte)),'jpg');
Res = 1;
close all;
end

Binary file not shown.

After

Width:  |  Height:  |  Size: 65 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 66 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 65 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 64 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 67 KiB

View File

@@ -0,0 +1,49 @@
% This function exports the given figure with nice settings to the given
% file path in the defined file format.
%
% input parameter:
% - handle ... figure handle
% - path ... file path
% - format ... file format ('pdf', 'meta', 'jpeg', 'png'), default 'pdf'
function exportFigure(handle, path, format)
% select figure
figure(handle)
% set output settings
set(gcf, 'PaperPositionMode', 'manual', 'Renderer', 'painters', 'RendererMode', 'manual');
% export figure
print(handle, path, '-dpdf');
% set export format
% if(strcmp(format,'pdf') || strcmp(format,'jpeg') )
% dformat = ['-d' format];
% else
% dformat = '-dpdf';
% end
%
% if(strcmp(format,'meta'))
% format = 'emf';
% end
%
% if(strcmp(format,'jpeg'))
% format = 'jpg';
% end
if(strcmp(format,'jpeg') || strcmp(format,'jpg') || ...
strcmp(format,'JPEG') || strcmp(format,'JPG'))
display(' --------------- Converting to JPG image ----------------- ');
system(['convert -density 300 ' path '.pdf -quality 95 ' path '.jpg']);
system(['rm ' path '.pdf']);
end
if(strcmp(format,'png') || strcmp(format,'PNG'))
display(' --------------- Converting to PNG image ----------------- ');
system(['convert -density 300 ' path '.pdf ' path '.png']);
system(['rm ' path '.pdf']);
end
end % end function

View File

@@ -0,0 +1,15 @@
function [c,r] = fitcircle2(x,y)
% Function to plot a linear least squares circle on a data set
% x = vector of x-coordinates
% y = vector of y-coordinates
% c = center of the circle
% r = radius of circle (not relevant)
n=length(x); xx=x.*x; yy=y.*y; xy=x.*y;
A=[sum(x) sum(y) n;sum(xy) sum(yy) sum(y);sum(xx) sum(xy) sum(x)];
B=[-sum(xx+yy) ; -sum(xx.*y+yy.*y) ; -sum(xx.*x+xy.*y)];
a=A\B;
xc = -.5*a(1);
yc = -.5*a(2);
r = sqrt((a(1)^2+a(2)^2)/4-a(3));
c = [xc;yc];
end

View File

@@ -0,0 +1,64 @@
function [mesure1,VarName4,VarName6,VarName8,VarName10] = importfile1(filename, startRow, endRow)
%IMPORTFILE1 Import numeric data from a text file as column vectors.
% [MESURE1,VARNAME4,VARNAME6,VARNAME8,VARNAME10] = IMPORTFILE1(FILENAME)
% Reads data from text file FILENAME for the default selection.
%
% [MESURE1,VARNAME4,VARNAME6,VARNAME8,VARNAME10] = IMPORTFILE1(FILENAME,
% STARTROW, ENDROW) Reads data from rows STARTROW through ENDROW of text
% file FILENAME.
%
% Example:
% [mesure1,VarName4,VarName6,VarName8,VarName10] = importfile1('mesure.txt',12, 550411);
%
% See also TEXTSCAN.
% Auto-generated by MATLAB on 2017/05/03 10:14:16
%% Initialize variables.
delimiter = '\t';
if nargin<=2
startRow = 12;
endRow = inf;
end
%% Format string for each line of text:
% column2: double (%f)
% column4: double (%f)
% column6: double (%f)
% column8: double (%f)
% column10: double (%f)
% For more information, see the TEXTSCAN documentation.
formatSpec = '%*s%f%*s%f%*s%f%*s%f%*s%f%[^\n\r]';
%% Open the text file.
fileID = fopen(filename,'r');
%% Read columns of data according to format string.
% This call is based on the structure of the file used to generate this
% code. If an error occurs for a different file, try regenerating the code
% from the Import Tool.
dataArray = textscan(fileID, formatSpec, endRow(1)-startRow(1)+1, 'Delimiter', delimiter, 'EmptyValue' ,NaN,'HeaderLines', startRow(1)-1, 'ReturnOnError', false);
for block=2:length(startRow)
frewind(fileID);
dataArrayBlock = textscan(fileID, formatSpec, endRow(block)-startRow(block)+1, 'Delimiter', delimiter, 'EmptyValue' ,NaN,'HeaderLines', startRow(block)-1, 'ReturnOnError', false);
for col=1:length(dataArray)
dataArray{col} = [dataArray{col};dataArrayBlock{col}];
end
end
%% Close the text file.
fclose(fileID);
%% Post processing for unimportable data.
% No unimportable data rules were applied during the import, so no post
% processing code is included. To generate code which works for
% unimportable data, select unimportable cells in a file and regenerate the
% script.
%% Allocate imported array to column variable names
mesure1 = dataArray{:, 1};
VarName4 = dataArray{:, 2};
VarName6 = dataArray{:, 3};
VarName8 = dataArray{:, 4};
VarName10 = dataArray{:, 5};

View File

@@ -0,0 +1,35 @@
function [Y] = myFit(x, y, start, End, file)
W = (y-y(1)) - (y(End-start)-y(1))/(x(End - start))*x;
A = [x ones(size(x))]\y;
a = A(1); b = A(2);
Y = y - (a*x + b);
fig = newFigure(16,20);
subplot(2,1,1);
plot (x, y, 'r');
grid on
xlabel ('Time (sec)', 'interpreter', 'latex')
ylabel ('Straightness $( \mu{} \mathrm{m})$', 'interpreter', 'latex')
title ('Straightness-Raw', 'interpreter', 'latex')
subplot(2,1,2);
plot (x, Y, 'color',[0 0.5 0]);
grid on
%ylim([-10 14]);
xlabel ('Time (sec)', 'interpreter', 'latex')
ylabel ('Straightness $( \mu{} \mathrm{m})$', 'interpreter', 'latex')
title ('Straightness-Corrected', 'interpreter', 'latex')
m= max(Y) - min(Y);
text(1,10, 'max - min =', 'interpreter', 'latex')
text(1,6, [num2str(m) ' $\mu{} \mathrm{m}$'], 'interpreter', 'latex')
string = { file };
Newstring = {string{1}(1:end-4)} ;
p= char(Newstring);
exportFigure(fig,p, 'png');
end

View File

@@ -0,0 +1,5 @@
function Y = myfit2(x,y)
A = [x ones(size(x))]\y;
a = A(1); b = A(2);
Y = y - (a*x + b);
end

View File

@@ -0,0 +1,270 @@
function hpol = polar2(varargin)
%POLAR2 Polar coordinate plot.
% POLA2R(THETA, RHO) makes a plot using polar coordinates of
% the angle THETA, in radians, versus the radius RHO.
% POLAR2(THETA,RHO,R) uses the radial limits specified by the two element
% vector R. If R is a 4-element vector, the second two elements are
% angular limits.
% POLAR2(THETA,RHO,S) uses the linestyle specified in string S.
% See PLOT for a description of legal linestyles.
% POLAR2(THETA,RHO,R,S) uses the linestyle specified in string S and the
% radial limits in R.
%
% POLAR2(AX,...) plots into AX instead of GCA.
%
% H = POLAR2(...) returns a handle to the plotted object in H.
%
% Example:
% t = 0:.01:2*pi;
% polar2(t,sin(2*t).*cos(2*t),[-2 2], '--r');
%
% See also PLOT, LOGLOG, SEMILOGX, SEMILOGY.
%
% Copyright 2009-2012 The MathWorks, Inc.
% Parse possible Axes input
[cax,args,nargs] = axescheck(varargin{:});
%error(nargchk(1,4,nargs,'struct'));
if nargs < 1 || nargs > 4
error('MATLAB:polar:InvalidInput', 'Requires 2 to 4 data arguments.')
elseif nargs == 2
theta = args{1};
rho = args{2};
if ischar(rho)
line_style = rho;
rho = theta;
[mr,nr] = size(rho);
if mr == 1
theta = 1:nr;
else
th = (1:mr)';
theta = th(:,ones(1,nr));
end
else
line_style = 'auto';
end
radial_limits = [];
elseif nargs == 1
theta = args{1};
line_style = 'auto';
rho = theta;
[mr,nr] = size(rho);
if mr == 1
theta = 1:nr;
else
th = (1:mr)';
theta = th(:,ones(1,nr));
end
radial_limits = [];
elseif nargs == 3
if ( ischar(args{3}) )
[theta,rho,line_style] = deal(args{1:3});
radial_limits = [];
else
[theta,rho,radial_limits] = deal(args{1:3});
line_style = 'auto';
if ( isempty(radial_limits) )
radial_limits = [];
elseif ( numel(radial_limits) == 2 )
radial_limits = [radial_limits(:); 0; 2*pi];
elseif ( ~(numel(radial_limits) == 4) )
error ( 'R must be a 2 element vector' );
end
end
else %nargs == 4
[theta,rho,radial_limits,line_style] = deal(args{1:4});
if ( isempty(radial_limits) )
radial_limits = [];
elseif ( numel(radial_limits) == 2 )
radial_limits = [radial_limits(:); 0; 2*pi];
elseif ( ~(numel(radial_limits) == 4) )
error ( 'R must be a 2 element vector' );
end
end
if ischar(theta) || ischar(rho)
error('MATLAB:polar:InvalidInputType', 'Input arguments must be numeric.');
end
if ~isequal(size(theta),size(rho))
error('MATLAB:polar:InvalidInput', 'THETA and RHO must be the same size.');
end
% get hold state
cax = newplot(cax);
next = lower(get(cax,'NextPlot'));
hold_state = ishold(cax);
% get x-axis text color so grid is in same color
tc = get(cax,'xcolor');
ls = get(cax,'gridlinestyle');
% Hold on to current Text defaults, reset them to the
% Axes' font attributes so tick marks use them.
fAngle = get(cax, 'DefaultTextFontAngle');
fName = get(cax, 'DefaultTextFontName');
fSize = get(cax, 'DefaultTextFontSize');
fWeight = get(cax, 'DefaultTextFontWeight');
fUnits = get(cax, 'DefaultTextUnits');
set(cax, 'DefaultTextFontAngle', get(cax, 'FontAngle'), ...
'DefaultTextFontName', get(cax, 'FontName'), ...
'DefaultTextFontSize', get(cax, 'FontSize'), ...
'DefaultTextFontWeight', get(cax, 'FontWeight'), ...
'DefaultTextUnits','data')
% only do grids if hold is off
if ~hold_state
% make a radial grid
hold(cax,'on');
set(cax,'dataaspectratio',[1 1 1],'plotboxaspectratiomode','auto')
% ensure that Inf values don't enter into the limit calculation.
%arho = abs(rho(:));
if ( isempty(radial_limits) )
maxrho = max(rho(rho ~= Inf));
minrho = min(rho(rho ~= Inf));
hhh=line([minrho minrho maxrho maxrho],[minrho maxrho maxrho minrho],'parent',cax);
v = [get(cax,'xlim') get(cax,'ylim')];
ticks = numel(get(cax,'ytick'));
delete(hhh);
% check radial limits and ticks
rmin = v(1); rmax = v(4); rticks = max(ticks-1,2);
if rticks > 5 % see if we can reduce the number
if rem(rticks,2) == 0
rticks = rticks/2;
elseif rem(rticks,3) == 0
rticks = rticks/3;
end
end
rinc = (rmax-rmin)/rticks;
else
thmax = radial_limits(4);
thmin = radial_limits(3);
rmax = radial_limits(2);
rmin = radial_limits(1);
order = (10^floor(log10(rmax-rmin)));
firstDigit = floor((rmax-rmin)/order);
if ( firstDigit <= 1 )
step = 0.2*order;
elseif ( firstDigit <= 3 )
step = 0.5*order;
elseif ( firstDigit <= 7 )
step = order;
else
step = 2*order;
end
rinc = step;
%Also, make sure to drop any values outside the limits.
if ( rmin == 0 )
subset = rho >= -rmax & rho <= rmax & theta >= thmin & theta <= thmax;
else
subset = rho >= rmin & rho <= rmax & theta >= thmin & theta <= thmax;
end
theta = theta(subset);
rho = rho(subset);
end
% define a circle
th = 0:pi/50:2*pi;
xunit = cos(th);
yunit = sin(th);
% now really force points on x/y axes to lie on them exactly
inds = 1:(length(th)-1)/4:length(th);
xunit(inds(2:2:4)) = zeros(2,1);
yunit(inds(1:2:5)) = zeros(3,1);
% plot background if necessary
if ~ischar(get(cax,'color')),
patch('xdata',xunit*(rmax-rmin),'ydata',yunit*(rmax-rmin), ...
'edgecolor',tc,'facecolor',get(cax,'color'),...
'handlevisibility','off','parent',cax);
end
% draw radial circles
c82 = cos(82*pi/180);
s82 = sin(82*pi/180);
for i=(rmin+rinc):rinc:rmax
hhh = line(xunit*(i-rmin),yunit*(i-rmin),'linestyle',ls,'color',tc,'linewidth',1,...
'handlevisibility','off','parent',cax);
text((i-rmin+rinc/20)*c82,(i-rmin+rinc/20)*s82, ...
[' ' num2str(i)],'verticalalignment','bottom',...
'handlevisibility','off','parent',cax)
end
set(hhh,'linestyle',':') % Make outer circle solid
% plot spokes
th = (1:6)*2*pi/12;
cst = cos(th); snt = sin(th);
cs = [-cst; cst];
sn = [-snt; snt];
line((rmax-rmin)*cs,(rmax-rmin)*sn,'linestyle',ls,'color',tc,'linewidth',1,...
'handlevisibility','off','parent',cax)
% annotate spokes in degrees
rt = 1.1*(rmax-rmin);
for i = 1:length(th)
text(rt*cst(i),rt*snt(i),int2str(i*30),...
'horizontalalignment','center',...
'handlevisibility','off','parent',cax);
if i == length(th)
loc = int2str(0);
else
loc = int2str(180+i*30);
end
text(-rt*cst(i),-rt*snt(i),loc,'horizontalalignment','center',...
'handlevisibility','off','parent',cax)
end
% set view to 2-D
view(cax,2);
% set axis limits
axis(cax,(rmax-rmin)*[-1 1 -1.15 1.15]);
setappdata( cax, 'rMin', rmin );
else
%Try to find the inner radius of the current axis.
if ( isappdata ( cax, 'rMin' ) )
rmin = getappdata( cax, 'rMin' );
else
rmin = 0;
end
end
% Reset defaults.
set(cax, 'DefaultTextFontAngle', fAngle , ...
'DefaultTextFontName', fName , ...
'DefaultTextFontSize', fSize, ...
'DefaultTextFontWeight', fWeight, ...
'DefaultTextUnits',fUnits );
% transform data to Cartesian coordinates.
xx = (rho - rmin).*cos(theta);
yy = (rho - rmin).*sin(theta);
% plot data on top of grid
if strcmp(line_style,'auto')
q = plot(xx,yy,'parent',cax);
else
q = plot(xx,yy,line_style,'parent',cax);
end
if nargout == 1
hpol = q;
end
if ~hold_state
set(cax,'dataaspectratio',[1 1 1]), axis(cax,'off'); set(cax,'NextPlot',next);
end
set(get(cax,'xlabel'),'visible','on')
set(get(cax,'ylabel'),'visible','on')
if ~isempty(q) && ~isdeployed
makemcode('RegisterHandle',cax,'IgnoreHandle',q,'FunctionName','polar');
end