How do I shorten and remove empty elements from a textscan cell array?
Mostrar comentarios más antiguos
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 comentarios
Stephen23
el 22 de Jul. de 2015
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
el 22 de Jul. de 2015
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.
Respuestas (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.
2 comentarios
Richard Lin
el 22 de Jul. de 2015
That is quite a complicated text file. A Star Strider has already asked you, exactly what information do you want to retrieve from this text file? If you tell us exactly what you are after then we can figure out an efficient way of doing it.
Categorías
Más información sobre Characters and Strings en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!