Selecting only the top half of values from a text document?
2 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
採用された回答
Abhi Sundararaman
2017 年 8 月 1 日
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.