- Codice:
clear all
n = 11; %number of csv files
n = n+2;
row11 = 529; %first line to be read (as shown in excel)TOP
row12 = 559; %second line to be read (as shown in excel)TOP
%row11 = 2916 ; %first line to be read (as shown in excel)BOTTOM
%row12 = 2944; %second line to be read (as shown in excel)BOTTOM
column1 = 4; %first column to be read (as shown in excel)
column2 = 4; %first column to be read (as shown in excel)
J = row12 - row11 + 1;
row11 = row11-2;
column1 = column1-1;
column2 = column2-1;
d = dir('C:\Users\Utente\Desktop\Gianmaria\G4\CSV4'); %legge tutti i file nella directory
for i = 3:n
i
filename = d(i).name;
for j = 1:J
m(j) = csvread(filename,row11+j,column1,[row11+j,column1,row11+j,column1]);
end
m1 = mean(m);
s(i,1) = m1;
end
xlswrite('C:\Users\Utente\Desktop\Gianmaria\G4\CSV4\extracted_Pt.xlsx',s,'Foglio1','A1');
Per migliorare il metodo mi è stato assegnato un secondo editor e ho dei dubbi nell'interpretarlo. Questa volta, al posto di mediare le x di due linee in posizione y, si deve mediare gli spostamenti lungo y di due quadratini (uno TOP e l'altro BOTTOM). Riporto sotto, come ho compilato:
- Codice:
clear all
n = 11; %number of csv files
space = 7; %number of steps in x direction, i.e. lines from x_min to x_max in the excel file
n = n+2;
row11 = 541; %first line to be read (as shown in excel)
row12 = 547; %second line to be read (as shown in excel)
row21 = 2928; %first line to be read (as shown in excel)
row22 = 2934; %second line to be read (as shown in excel)
column1 = 4; %first column to be read (as shown in excel)
column2 = 4; %first column to be read (as shown in excel)
J = row12 - row11+1;
row11 = row11-2;
row21 = row21-1;
column1 = column1-1;
column2 = column2-1;
d = dir('C:\Users\Utente\Desktop\Gianmaria\G4\CSV4'); %legge tutti i file nella directory
m = zeros(1,J);
r = zeros(1,J);
m1 = zeros(1,J);
m2 = zeros(1,J);
s = zeros(n,2);
for i = 3:n
i
filename = d(i).name;
for k =1:J
for j = 1:J
m(j) = csvread(filename,row11+j+(k-1)*space,column1,[row11+j+(k-1)*space,column1,row11+j+(k-1)*space,column1]);
r(j) = csvread(filename,row21+j+(k-1)*space,column2,[row21+j+(k-1)*space,column2,row21+j+(k-1)*space,column2]);
end
m1(k)= mean(m);
m2(k)= mean(r);
end
m3 = mean(m1);
m4 = mean(m2);
s(i,1) = m3;
s(i,2) = m4;
end
xlswrite('C:\Users\Utente\Desktop\Gianmaria\G4\CSV4\extracted.xlsx',s,'Foglio1','A1');
Ho dei dubbi sul termine "space" e cosa mettere in row11, row 12, row 21 e row 22. Questa volta si esporta un excel con due colonne, penso una per lo spostamento TOP e una per lo spostamento BOTTOM. Per ora ho ristretto l'intervallo delle x (non più tutta la larghezza del provino) e 7 di "space" sarebbe il numero di righe dei valori lungo x. La colonna 4 dei file presi e utilizzati nel metodo riporta gli spostamenti lungo y.
Conosco molto poco MatLab e mi sarebbe d'aiuto anche una spiegazione delle diverse linee di codice.
Grazie mille