How do I shorten and remove empty elements from a textscan cell array?
이전 댓글 표시
Here's my code
FILE_NAME='17.5x5burnerAug28_2014y25CEA180scool.txt';
file=fopen(FILE_NAME);
file_strings=textscan(file,'%s','delimiter','\t');
fclose(file);
help = 0;
while help < 138488
help = help +1;
if strcmp(file_strings{1}{help}, '')
file_strings{1}(help) = [];
disp(help);
end
end
When I run this code, all of the empty string elements in the cell array remain in the same index, and the size of the cell array remains the same. I want to be able to delete each empty element in the cell array.
댓글 수: 2
Stephen23
2015년 7월 22일
This time I formatted your code correctly for you, but in future please format it yourself by selecting the code and then clicking the {} Code button that you will find above the textbox.
Star Strider
2015년 7월 22일
What information do you want from your text file?
It has several lines of header information, then a large number of different matrices with essentially the same header and numerical format, apparently from different experiments.
답변 (1개)
file_name = '17.5x5burnerAug28_2014y25CEA180scool.txt';
fid = fopen(file_name,'rt');
C = textscan(file,'%s','delimiter','\t');
fclose(file);
out = C{1}(~cellfun('isempty',C{1}(:,1)),:);
You do not actually give any sample data and do not tell us how many rows and columns this data has, so I tried to make it work for multiple columns, but it is untested as I do not have your data.
카테고리
도움말 센터 및 File Exchange에서 Characters and Strings에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!