Multiple file loading matlab
<p>I want to load multiple files in few folders and to plot figures for each. I'm quite naive to matlab environment, I did something dirty like this!:</p>

<pre><code>foldername1='K_S/';
foldername2='L_J/';
foldername3='P_O/';

extension='*.pro';

name1=strcat(foldername1, extension);
name2=strcat(foldername2, extension);
name3=strcat(foldername3, extension);

fileset1=dir(name1);
fileset2=dir(name2);
fileset3=dir(name3);

a = [];
b = [];
c = [];

for i = 1:length(fileset1)

    a=load(strcat(foldername1, fileset1(i).name)); 
    b=load(strcat(foldername2, fileset2(i).name)); 
    c=load(strcat(foldername3, fileset3(i).name)); 


    figure
    sub1=plot(a(:,1),a(:,2),'b'), hold on
    sub2=plot(a(:,1),a(:,3),'r')
    ylabel('score')
    xlabel('trial')
    legend([sub1, sub2],'sub1','sub2')
    legend boxoff
    title(sprintf('Dyad K S: %d',i));
    axis square

    figure
    sub1=plot(b(:,1),b(:,2),'b'), hold on
    sub2=plot(b(:,1),b(:,3),'r')
    ylabel('score')
    xlabel('trial')
    legend([sub1, sub2],'sub1','sub2')
    legend boxoff
    title(sprintf('Dyad L J: %d',i));
    axis square

    figure
    sub1=plot(c(:,1),c(:,2),'b'), hold on
    sub2=plot(c(:,1),c(:,3),'r')
    ylabel('score')
    xlabel('trial')
    legend([sub1, sub2],'sub1','sub2')
    legend boxoff
    title(sprintf('Dyad P O: %d',i));
    axis square

end
</code></pre>

<p>Any help would be appreciated on how to make it smarter.</p>

<p>Thank you!</p>