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!