MATLAB Answers

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

6 views (last 30 days)
Victor Szenes
Victor Szenes on 7 Apr 2021
Edited: Stephen Cobeldick on 7 Apr 2021
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
"Page 1 of 600"
i already tried something like this, but the syntax ist not correct:
for i=1:length(a)
data_new5=data_new4(data_new4~="page %d of 600",);
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.!!!

Answers (1)

Stephen Cobeldick
Stephen Cobeldick on 7 Apr 2021
Edited: Stephen Cobeldick on 7 Apr 2021
tmp = sprintf("page %d of 600",i);
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+$'))

Community Treasure Hunt

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

Start Hunting!