How to delete certain strings with chaning numbers in a big data set

1 view (last 30 days)
Hello community
I am new to matlab, watched already some tutorials to understand the basics I spent two days trying to do this and I'm literally pulling my hair out. Any help would be massively appreciated!
I have an array with more than 16k entries, which includes a lot of unnecessary informations and I wan to delete the some strings like "name", "Pat-ID" - that was not that difficult and I solved the problem quick and simple with: a = a(a~="name")
BUT I have massive problems to solve following example: I downloaded the data from a database and imported also the page numbers --> I want to delete the strings with a changing page number like this: "page X of 600" --> X=1-600
example of the data set: array with one column:
name XYZ
birthdate
ID
"Page 1 of 600"
...
i already tried something like this, but the syntax ist not correct:
for i=1:length(a)
d=i;
data_new5=data_new4(data_new4~="page %d of 600",);
end
I also tried to solve it with a for loop but unfortunately it didnt work.
I think that problem ist not that difficult but for a newcomer its just a little bit hard to get over it.
Thanks in advance.
stay safe.!!!
I

Answers (1)

Stephen23
Stephen23 on 7 Apr 2021
Edited: Stephen23 on 7 Apr 2021
tmp = sprintf("page %d of 600",i);
data_new4~=tmp
Or
~strcmpi(data_new4,tmp)
Note that you will want to replace the previous data array on each loop iteration.
Or skip the loop by judicious usage of StartWith and EndsWith. Or use a regular expression, e.g.:
~cellfun(@isempty,regexp(data_new4,'^page \d+ of \d+$'))

Categories

Find more on Characters and Strings in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!