Selecting only the top half of values from a text document?
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Jeremy
am 28 Jul. 2017
Kommentiert: Jeremy
am 1 Aug. 2017
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];
0 Kommentare
Akzeptierte Antwort
Abhi Sundararaman
am 1 Aug. 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.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Characters and Strings finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!