reading in text files
14 comentarios
You're only getting one file because you're overwriting M each time you read the next file. You need to index M. I would suggest using cell arrays.
M(k) = {dlmread(textFilename,' ',1,0)};
To the best of my knowledge dlmread(), or any importer command besides xlsread(), cannot import only specific columns. You're going to need to import then entire thing and then redefine the matrix to only include the desired columns. This can be done in a new matrix, or by just redefining the old.
M{k} = M{k}(:,[1,2,3,6]); % Reshape original, all data outside of columns
% 1,2,3, and 6 will be lost
N{k} = M{k}(:,[1,2,3,6]); % Make a new matrix, keep all of the original
% data in M for later use
Anything contained within the parentheses following an array is the indexing. Using [1,2+10000,3+10000,6] is still specifying a location, so it will look for columns 1, 6, 10002, and 10003. If you want to just add values then you need to do so outside of the indexing operation.
T{k}(:,[1,4]) = M{k}(:,[1,6]);
T{k}(:,[2,3]) = M{k}(:,[2,3]) + 10000;
Yes, it is possible to sort things based on specific values of rows. Going back to our previous example:
T{k} = T{k}(T{k}(:,4)==4||T{k}(:,4)==9||T{k}(:,4)==12||T{k}(:,4)==15||T{k}(:,4)==17,:);
% Note that this removes all other values of T{k}. If you want to keep them
% you need to save them as a different variable. Also note that all of the
% right side of the equation is indexing, there is no value adjustment.
Basically, you can include logic challenges in your indexing.
Respuestas (1)
8 comentarios
dinfo = 'C58501_line_ssF_%04d.txt';
pathToFiles = {dinfo.name};
ds = tabularTextDatastore(pathToFiles) ds.SelectedVariableNames = ds.SelectedVariableNames([1,2,3,6]);
while hasdata(ds) T = read(ds) % do stuff end
Categorías
Más información sobre Text Files en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!