Hi,
I need to find some strings in a file, but it has to match only the whole word. I have some variables which I have to change but as some are variables like t, a, etc. If I do not use a whole word match everything is changed. The equations are created by the simbolic toolbox, so that searching for spaces between the variables is not a possibility.
I am doing it using fprintf and the command regexprep but I dont know how to make it to search only for whole words.
example:
F_dr = t*(gt-ha)+2*a-1.
I need to change t to t_1 and a to A2 but gt and ha should stay as they are:
F_dr = t_1*(gt-ha)+2*A2-1.
|
|
0
|
|
|
|
Reply
|
nico
|
1/7/2011 4:27:05 PM |
|
"nico cruz" <m.nicolas.cruz@mailbox.tu-berlin.de> wrote in message <ig7esp$d1a$1@fred.mathworks.com>...
> Hi,
>
> I need to find some strings in a file, but it has to match only the whole word. I have some variables which I have to change but as some are variables like t, a, etc. If I do not use a whole word match everything is changed. The equations are created by the simbolic toolbox, so that searching for spaces between the variables is not a possibility.
>
> I am doing it using fprintf and the command regexprep but I dont know how to make it to search only for whole words.
>
> example:
>
> F_dr = t*(gt-ha)+2*a-1.
>
> I need to change t to t_1 and a to A2 but gt and ha should stay as they are:
>
> F_dr = t_1*(gt-ha)+2*A2-1.
syms t gt ha a
F_dr = t*(gt-ha)+2*a-1;
% Define the variables you want to substitute
syms t_1 A2
% Use subs
subs(F_dr,{t,a},{t_1,A2})
And don't use gt since it's a built-in matlab function.
Oleg
|
|
0
|
|
|
|
Reply
|
Oleg
|
1/7/2011 4:56:04 PM
|
|
"Oleg Komarov" <oleg.komarovRemove.this@hotmail.it> wrote in message <ig7gj4$32o$1@fred.mathworks.com>...
> "nico cruz" <m.nicolas.cruz@mailbox.tu-berlin.de> wrote in message <ig7esp$d1a$1@fred.mathworks.com>...
> > Hi,
> >
> > I need to find some strings in a file, but it has to match only the whole word. I have some variables which I have to change but as some are variables like t, a, etc. If I do not use a whole word match everything is changed. The equations are created by the simbolic toolbox, so that searching for spaces between the variables is not a possibility.
> >
> > I am doing it using fprintf and the command regexprep but I dont know how to make it to search only for whole words.
> >
> > example:
> >
> > F_dr = t*(gt-ha)+2*a-1.
> >
> > I need to change t to t_1 and a to A2 but gt and ha should stay as they are:
> >
> > F_dr = t_1*(gt-ha)+2*A2-1.
>
> syms t gt ha a
> F_dr = t*(gt-ha)+2*a-1;
>
> % Define the variables you want to substitute
> syms t_1 A2
> % Use subs
> subs(F_dr,{t,a},{t_1,A2})
>
> And don't use gt since it's a built-in matlab function.
>
> Oleg
Thank you for the post Oleg. I am working with the orginial poster - allow me to clarify the problem.
We need to work with symbolics in order to create some expressions, and we need to then convert the variable names to use for a different purpose, outside of matlab.
I liked your idea, because in our case it would mean simply converting the variable names before converting to strings (which we need as our output). However, our variable names need to be changed to experessions that are invalid as variables in matlab.
For example, here are two of our variables, and the expressions they need to be converted to:
'KHSTO' ------> 'K_{HSTO}^{A}'
'T' ------> 'T^{A}'
So, the original solution was to convert to strings, and then replace, but then 'T' is found in both of the above variables. And we can not convert to the desired variables with symbolics because they are invalid.
thanks again for any help.
|
|
0
|
|
|
|
Reply
|
kavon
|
1/7/2011 5:25:21 PM
|
|
|
2 Replies
567 Views
(page loaded in 0.426 seconds)
Similiar Articles: find string matching whole word - comp.soft-sys.matlabHi, I need to find some strings in a file, but it has to match only the whole word. I have some variables which I have to change but as some are va... find string in file - comp.unix.shellfind string matching whole word - comp.soft-sys.matlab Hi, I need to find some strings in a file, but it has to match only the whole word. I have some variables which I ... Find word, replace line - comp.lang.awkfind string matching whole word - comp.soft-sys.matlab Find word, replace line - comp.lang.awk find string matching whole word - comp.soft-sys.matlab Find word, replace ... Finding files which does not contain a specific string - comp.unix ...find string matching whole word - comp.soft-sys.matlab Finding files which does not contain a specific string - comp.unix ... find string matching whole word - comp.soft ... Bash Test for Partial Match of String - comp.unix.shellfind string matching whole word - comp.soft-sys.matlab Bash Test for Partial Match of String - comp.unix.shell find string matching whole word - comp.soft-sys.matlab fuzzy ... (sh/bash) How to check for a string matching -*? - comp.unix.shell ...find string matching whole word - comp.soft-sys.matlab (sh/bash) How to check for a string matching -*? - comp.unix.shell ... find string matching whole word - comp.soft ... Join two lines in pattern matching, search, then assign fields to ...find string matching whole word - comp.soft-sys.matlab Join two lines in pattern matching, search, then assign fields to ... find string matching whole word - comp.soft ... search for a string in a file using expect.. - comp.lang.tcl ...find string matching whole word - comp.soft-sys.matlab search for a string in a file using expect.. - comp.lang.tcl ... find string matching whole word - comp.soft-sys ... how to match "$" in expect, instead of using it as a wildcard ...find string matching whole word - comp.soft-sys.matlab search for a string in a file using expect.. - comp.lang ... Hi, I d like to use .NET regular expression class to ... Grep string with spaces - comp.unix.shellfind string matching whole word - comp.soft-sys.matlab The equations are created by the simbolic toolbox, so that searching for spaces ... the files using ... of the files ... find string matching whole word - comp.soft-sys.matlab | Computer ...Hi, I need to find some strings in a file, but it has to match only the whole word. I have some variables which I have to change but as some are va... find string matching whole word - Newsreader - MATLAB CentralHi, I need to find some strings in a file, but it has to match only the whole word. I have some variables which I have to change but as some are variables like t, a, etc. 7/27/2012 10:15:42 AM
|