How can I extract the all the rows that contain a certain string from a cell array?
101 次查看(过去 30 天)
显示 更早的评论
I am a MATLAB novice and stumped by a seemingly easy thing: I am analysing frequency reserve and unfortunately my Excel data for a certain amount of time looks like this:
frequency_type_a 190 35 5
frequency_type_a 50 55 6
frequency_type_a 60 200 10
frequency_type_b 170 89 6
frequency_type_b 83 35 15
frequency_type_c 200 64 17
frequency_type_c 89 32 15
So the problem is that all the different types of reserve are in the file - however I just want to analyse one type. I could use a import wizard, however I will be needing to do this for +100 files and don't want to click myself through the import manager every time! I have tried this so far:
[num text raw] = xlsread('ERGEBNISLISTE_ANONYM_SRL_2014-06-02.CSV');
typeb(raw(:,2)=='frequency_type_b')
The error message says: ??? Undefined function or method 'eq' for input arguments of type 'cell'. So I'm guessing that only works for numbers in Matrices. I have also looked at cat, match and writing a if-function, but none of them seemed doable.Is there a way to solve my problem? Maybe even a different approach, like only loading a specific type in the first place?
Any help is much appreciated!
0 个评论
采纳的回答
James Tursa
2015-7-8
编辑:James Tursa
2015-7-8
Don't use == (the eq function) to compare strings since this is an element-by-element operator. Use a function meant for this purpose instead. E.g.,
strcmp(raw(:,2),'frequency_type_b')
This result will be a logical vector that you can use to index into and extract your desired data from other matrices.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!