Hello All,
I would like to write a scrip that will open multiple tab delimited, headerless .txt files from a folder (ex file name "Test1" "Test2" etc) and have the second column copied into an array of zeroes. So far I have tried to follow a similar case I found here:
%This scrip is designed to open multiple .txt files containing %data and write the second column of data into an array.
%1)Set-up File Directory
%Copy folder path here:
MyFolder = Users/Chris/Desktop/Test;
TextFiles = dir(Users/Chris/Desktop/Test .txt);
%Create and array of zeros to rewrite data over
Absorbance = zeroes (2048, 63); %2048 x values and ## spectra files
%3)Import Absorbance Data
for i = 1:63 %Number of spectra files in directory
TextFileNames = ['Test_Absorbance_' num2str(k) '.txt']; %Open Text File, 'rt' = read text (only works for txt files)
fid = fopen(TextFileNames, 'rt'); %Read file into 2 separate variables
Data = textscan (fid, '%d%d', 2); %4)Wrtie Abs. data to array
%Insert absorbance data into array
Absorbance(:,k+1) = Data {2}; %put in 2nd row of data
fclose(fid);
end
the code-error alert icon in the upper right is green, however when I run the scrip I get an "undefined function or variable 'Users' error. I tried switching the path to ~Desktop\Test and get the same error. I would appreciate if someone could explain what the proper command should be.
Thank you in advance,
Best Answer