Run loop for multiple text files
Afficher commentaires plus anciens
[EDIT: Fri May 27 04:38:19 UTC 2011 - Reformat - MKF]
I want to run a loop, then build a matrix for 8 data files. Error message: Undefined function or variable 'data'. keeps popping up. what do I do?
%Data for BrainZ sample_i, for i=1:8,
%[Data] -> [N' i] , 24(rows) by 2(col), for BrainZ sample_i, for i = 1:8
%col(1) = Region of Interest sample #, col(2) = mean density (tab delimited data)
%row = all measurements(1:24)
files = dir('*.txt');
for i=1:length(files)
load(files(i).name);
end
%Re-arrange [Data] to form new matrix [A]
%[A] -> [N" i] = 4(rows) by 6(col), of BrainZ sample_i, for i = 1:8
%row = measurement_h, for h = 1:4, from Region of Interest (ROI)
%col = ROI = [mU mM mL bU bM bL]
%Monoc Upper = mU, Monoc Middle = mM, Monoc Lower = mL, Bi Upper = bU, Bi Middle = bM, Bi Lower = bL
for n=1:1:size(data,1)
if n<=4
mU(n)=data(n,2);
elseif n>=5 && n<=8
mM(n)=data(n,2);
elseif n>=9 && n<=12
mL(n)=data(n,2);
elseif n>=13 && n<=16
bU(n)=data(n,2);
elseif n>=17 && n<=20
bM(n)=data(n,2);
elseif n>=21 && n<=24
bL(n)=data(n,2);
else
end;
end;
mU(mU == 0) = [];
mM(mM == 0) = [];
mL(mL == 0) = [];
bU(bU == 0) = [];
bM(bM == 0) = [];
bL(bL == 0) = [];
A = cat(2, mU', mM', mL', bU', bM', bL')
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Data Import and Analysis dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!