필터 지우기
필터 지우기

delete elements from a cell array

조회 수: 2 (최근 30일)
elisa ewin
elisa ewin 2017년 6월 21일
편집: Andrei Bobrov 2017년 6월 22일
Hi!
I have a cell array b (attached); in each cell of b I have an expression like this: 'Weather booming Chilli Relax https://t.co/pwp00Ndw3d' or expressions with @,#,$. I want to delete from these expressions all the characters like @,#,$ and the links like https://t.co/pwp00Ndw3d.
Example: if I have 'Weather booming @Chilli Relax# https://t.co/pwp00Ndw3d', I will want it becames 'Weather booming Chill Relax'
Can you help me? thanks
  댓글 수: 3
elisa ewin
elisa ewin 2017년 6월 22일
sorry, now I re-write the question
Jan
Jan 2017년 6월 22일
편집: Jan 2017년 6월 22일
Weather booming Chilli Relax https://t.co/pwp00Ndw3d
This looks strange. It reminds me to Google: Britney Spears Instagram account used by hackers.
Perhaps I'm too distrustful, but I've modified the URL slightly to be sure. This does not change the core of the question or the answer. Sorry, these are hard times in the world wide web. Please do not take this personally.

댓글을 달려면 로그인하십시오.

채택된 답변

Andrei Bobrov
Andrei Bobrov 2017년 6월 22일
regexprep(b,'[$#@]|\<https:/+\S*\>','')
  댓글 수: 8
elisa ewin
elisa ewin 2017년 6월 22일
yes
Andrei Bobrov
Andrei Bobrov 2017년 6월 22일
편집: Andrei Bobrov 2017년 6월 22일
Hi Jan! Yes! "Russian rocket". :)
regexprep(b,'\<[^A-Za-z \?\,]|https:/+\S*\>','')

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Jan
Jan 2017년 6월 22일
편집: Jan 2017년 6월 22일
S = 'Weather booming Chilli Relax https://t.co/pwp00Ndw3d';
C = strsplit(S, ' ');
C(contains(C, '/')) = []; % Or how you identify a link
for iC = 1:numel(C)
aC = C{iC};
C{iC} = aC(isstrprop(aC, 'alphanum'));
end
Result = sprintf('%s ', C{:});
Result(end) = [];
The command contains was introduced in R2016b. If you have an older version, use:
function Tf = contains(C, Patterm)
Tf = ~cellfun('isempty', strfind(C, Pattern));
end

카테고리

Help CenterFile Exchange에서 File Name Construction에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by