clc
close all
clear

format

    d = dir('*.csv');
    
    smallest_index = 0;
    
    biggest_index = 0;
    
for i = length(d):-1:1
    Dstr_max_structure(i).name = d(i).name;
    Dstr_max_structure(i).matrix = csvread(d(i).name);
    
    if i == 4
        sizex = size(Dstr_max_structure(i).matrix(:,2),1);
    end

    if size( Dstr_max_structure(i).matrix(:,2) , 1 ) < sizex
        smallest_index = i;
    end
    
    %if size( Dstr_max_structure(i).matrix(:,2) , 1 ) > sizex
    %    biggest_index = i;
    %end
end

SmallestSize = size(Dstr_max_structure(smallest_index).matrix(:,2),1) - 1;
tensao = zeros(SmallestSize, length(d));
angulo = zeros(SmallestSize, length(d));


for i = 1:length(d)
     %aqui crio variaveis com os nº de dados igual ao mais pequeno!
    tensao(:,i) = Dstr_max_structure(i).matrix(1:SmallestSize,2);
    angulo(:,i) = Dstr_max_structure(i).matrix(1:SmallestSize,3);
end

 corrTensao = triu( corr(tensao , tensao) , 1 );
 corrAngulo = triu( corr(angulo , angulo) , 1 );
 
 corrTensaoSTD = [];
 corrAnguloSTD = [];
 
 for n = 1:numel(corrTensao)
     
     if corrTensao(n) > 0
         corrTensaoSTD = [ corrTensaoSTD corrTensao(n) ];
         corrAnguloSTD = [ corrAnguloSTD corrAngulo(n) ];
     end
     
 end
 
 mediaCorrTensao = mean(corrTensaoSTD)
 mediaCorrAngulo = mean(corrAnguloSTD)
 
 desvioCorrTensao = std(corrTensaoSTD)
 desvioCorrAngulo = std(corrAnguloSTD)
 
 Dstr_max_structure(1).name
 