Matlab help — How to replace a word using findstr?

  • Context: MATLAB 
  • Thread starter Thread starter tdang
  • Start date Start date
  • Tags Tags
    Matlab
Click For Summary
SUMMARY

This discussion focuses on replacing words in strings using MATLAB's findstr function and array concatenation. The user seeks to transform the sentence "I love flower" into "I hate flower" by replacing the word "love" with "hate". It is emphasized that for accurate replacements in larger documents, whole word matching and case insensitivity are crucial. The discussion also highlights the utility of MATLAB's regular expressions and the strrep function for string manipulation.

PREREQUISITES
  • Understanding of MATLAB programming language
  • Familiarity with string manipulation functions in MATLAB
  • Knowledge of regular expressions in MATLAB
  • Basic concepts of array concatenation in MATLAB
NEXT STEPS
  • Explore MATLAB's strrep function for string replacement
  • Learn about regular expressions in MATLAB for advanced string matching
  • Research the findstr function and its limitations in MATLAB
  • Investigate array concatenation techniques in MATLAB for string manipulation
USEFUL FOR

This discussion is beneficial for MATLAB programmers, data analysts, and anyone involved in text processing and string manipulation within MATLAB environments.

tdang
Messages
1
Reaction score
0
TL;DR
How to replace a word using findstr
Matlab help!
Hello
I want to create a sentence 2

sen1: I love flower
str1: love
str2: hate

How can I create sen2= "I hate flower" using findstr and array concatenation?
 
Physics news on Phys.org
In any case, for reliable use in large documents, you should do something to only replace whole words and to match regardless of capitalization. I am sure that MATLAB has some regular expressions to allow that.
 
There is an extrensive documentation from Matlab on strings here which should cover everything you need. Take a look at strrep for example.
 
  • Like
Likes   Reactions: FactChecker

Similar threads

  • · Replies 4 ·
Replies
4
Views
4K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 11 ·
Replies
11
Views
3K
Replies
5
Views
3K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 4 ·
Replies
4
Views
4K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 6 ·
Replies
6
Views
4K