Find and replace multiple string in MATLAB [closed] - matlab

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 1 year ago.
Improve this question
I have a1 in the following form in MATLAB.
a1{1,1} = {'x1','x2','x3'}
a1{1,2} = {'x1','x2','x3','x4'}
a1{1,3} = {'x4'}
I need to replace
'x1' with 'Text1'
'x2' with 'Text2'
'x3' with 'Text3'
'x4' with 'Text4'
I have tried a couple of things with no success and I am a bit lost, does anyone have any ideas.
Thanks

Regular Expressions might be a way to go with this
a1{1,1} = {'x1','x2','x3','x4'};
a1{1,1} = regexprep(a1{1,1},'x([0-9])','text$1');
Will result in a1{1,1} containing
{'text1'} {'text2'} {'text3'} {'text4'}
This will work for any single digit numerical value (0-9) that is prefixed with the letter x.

Related

sed - how to create all possible variations of name combinations [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
I cannot seem to find a clever way of creating all possible variations of name combinations.
Input (multiple names put together where each name is represented as a letter):
ABC (e.g. JohnPeterSarah)
pattern space: Replaces A with 1, B with 2 and C with 3 (among other -that's where you come in)
Desired Output
ABC
A2C
A23
AB3
1BC
12C
1B3
sed is not the most natural tool for this task. Try bash's brace expansion:
$ printf "%s\n" {A,1}{B,2}{C,3}
ABC
AB3
A2C
A23
1BC
1B3
12C
123
Its not clear what you are trying to do here but it sounds like you want all permutations of a string. The best way to do that is using recursion. This question was already addressed here.

Could you please tell me what this line do: sed 's/^.*-svn\([0-9]*\).*$/\1/' [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
Could you please tell me what this line do of sed
the expression is on the title
Thank you
Best regards
It replaces everything on the line with the number immediately following "-svn".
eg.:
blahblabhlabhlabhalbh-svn12345blahblhablhab
is replaced by:
12345
It's matching a string of [anything]-svn[numbers][anything], and replacing the line with the [numbers].
For example:
asda-svn123123bebeb
Gets replaced with
123123

How to keep a specific set of characters from a string using regular expression in PERL [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
I have this string
$eq= "ew';##rfhnbgsu.,/><hdjsdedokk";
By Perl I want to extract just the characters w, h, n, s, and f from the string.
The output should be like this
whhfnss
Could you help me?
say $s =~ /[whnsf]/g;

Unexpected MATLAB expression? (trying to create a function) [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
load('matrix.mat');
userInput = input('input a value from 1-5')
DayReport = sum(matrix(:,end 2);==userInput)
I am trying to retrieve the number of rows in column 2 of the loaded matrix that corresponds with the userInput. However, when I try to run the code, it says that there is an error in the third line (simply, "Unexpected MATLAB expression"). Any ideas as to why this is?
EDIT: I found a solution, turns out i don't need the "end" or the semicolon within the sum function.
load('matrix.mat');
userInput = input('input a value from 1-5')
DayReport = sum(matrix(:,2)==userInput)
Remove the semi-colon and the end statement in the last line of code. My guess is that you want to access the second column of matrix, and with that it's just matrix(:,2).
Also, I suspect that you copied and pasted the code from somewhere. That's generally bad programming practice because where you copied the code from may work in that situation, but if you try and bring it into your current context, it may be slightly different than what you're actually doing and can result in errors.
See this good discussion on Programmers Stack Exchange on why you should avoid this all together: https://softwareengineering.stackexchange.com/questions/87696/is-copy-paste-programming-bad

Is this a vaild variable name? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
For those that have experience in PowerShell, is this considered to be a valid variable name?
Code:
$[?#+-stuff] is a valid variable name in PowerShell.
It's a valid? Yes, if you wrap it inside curly brackets. This is required because of the special characters.
${[?#+-stuff]} = "foo"
Is it a good name? No. You should keep it simple..
If you made an effort to research it you would have figured it out yourself.
Check of the help documentation the #mjolinor suggested. Especially the part called:
VARIABLE NAMES THAT INCLUDE SPECIAL CHARACTERS
We're all here to help each other, so please show us some respect and behave like a grown-up.