Selecting only the top half of values from a text document?

1 visualización (últimos 30 días)
I am trying to place data from a text document to a table in GUI format. However, I only need the first half of the data to be inserted into one of the columns and then the bottom half of the data to be inserted into another column. Any suggestions? Obviously the code below is incorrect. Thank you in advance.
fileID = fopen(fullfile(folder,Unifile),'r');
alldata = textscan(fileID,...
[repmat('%s',[1 14]),'%s'],'HeaderLines',10);
fclose(fileID);
nlines = length(alldata{1});
nlinestop = nlines/2
Frequency = str2num(strvcat(alldata{7}));
SingleVelocityraw = str2num(strvcat(alldata{4}));
AllVelocity = str2num(strvcat(alldata{4}));
SingleVelocity = SingleVelocityraw([1, nlinestop]);
S.tFR.Data = [Frequency SingleVelocity AllVelocity];
S.tFR_Pos = tAll_Pos;
S.tFR.ColumnEditable = [false true true true false];

Respuesta aceptada

Abhi Sundararaman
Abhi Sundararaman el 1 de Ag. de 2017
Is each line of the data one entry in the table? That is, are you taking the top half of lines to be put into one column, and the bottom half into the other column? If that is the case, then you could do so by just reading the file, getting the halfway point, and indexing into the "alldata" vector.
For a simple case, with just a column of numbers in the text file that you wished to split in two, you could do this:
fileID = fopen('testfile.txt','r');
alldata = textscan(fileID, '%d');
fclose(fileID);
midline = length(alldata{1})/2;
tophalf = alldata{1}(1:midline);
bottomhalf = alldata{1}(midline:end);
This would result in the top half of the text document in one cell array, and the other half in another.

Más respuestas (0)

Categorías

Más información sobre Characters and Strings en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by