How to remove rows with any string from matrix
显示 更早的评论
Hello,
I'm trying to remove any rows that have any strings in them in my matric, for example:
name and other jibberish
1 0
0 1
0 2
another name and other words
0 3
1 0
other tosh
and change this to just:
1 0
0 1
0 2
0 3
1 0
so you can see, it doesn't matter what the string is, its not specific to what the letters in the string are, I just want it removed. Is there an easy way of doing this?
Thanks
3 个评论
José-Luis
2014-6-25
Is your matrix a cell array? Or are you trying to import a text file?
Aidan O'Farrell
2014-6-25
Jos (10584)
2014-6-25
For this, my solution should work.
采纳的回答
更多回答(1 个)
Azzi Abdelmalek
2014-6-25
编辑:Azzi Abdelmalek
2014-6-25
fid = fopen('file.txt');
res={};
while ~feof(fid)
res{end+1,1} =fgetl(fid);
end
fclose(fid);
res(cellfun(@(x) any(isletter(x)),res))=[]
out=cell2mat(cellfun(@str2num,res,'un',0))
类别
在 帮助中心 和 File Exchange 中查找有关 Cell Arrays 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!