Two words inside brackets in Matlab? [duplicate] - arrays

This question already has an answer here:
What is the difference between comma separated or not MATLAB function return?
(1 answer)
Closed 6 years ago.
What's that syntax for?
[sbox idx] = sort(box);
After reading Sort array elements, I would expect to see something like this:
[sbox, idx] = sort(box);
but that's not the case as you can see (it's an open sourced project, so it's not mine code). What does it mean?

Both lines do exactly the same, like [1 2 3 4] and [1,2,3,4] define the same vector.

Related

Should I put semicolons after JSX expression? [duplicate]

This question already has answers here:
What are the rules for JavaScript's automatic semicolon insertion (ASI)?
(7 answers)
Closed 7 months ago.
If I have the following:
...
let p1 = <p>qwer</p>
let p2 = <p>asdf</p>
...
Should I put semicolons at the end of each of these?
It is not wrong to leave it like that, you can put semicolons if you want, but it is better you be consistent and follow one code style check https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode
it will make your life easier

Any append (Python) or push_back (C++) equivalent in C? [duplicate]

This question already has an answer here:
Python-like array filling - C equivalent
(1 answer)
Closed 2 years ago.
I'm looking for an "append" (Python) or "push_back" (C++) equivalent in C to fill an array of strings (char). Does it exists?
The question doesn't make sense because you cannot add elements to an array in C. In C, you set the size of the array when you create it, and the size cannot change.
If you want to "append", you have to create a big array (e.g. 1000 items), and use a separate variable to remember how many items you're actually using (the rest are spare).

What would the regex be [duplicate]

This question already has an answer here:
Learning Regular Expressions [closed]
(1 answer)
Closed 6 years ago.
Here's my question I was given: Write a regular expression to recognize strings with that have any number of a's, b's and c's in the order of abc. However, any number of d's may be among the a's, b's and c's.
Positive Examples:
dddaddbcdd
dddd
Negative examples:
dabcddadbdd
because 2nd sequence starts but does not finish.
ddcdd because c without leading ab
ddaddbddcaddbcdd because 2 abc sequences
Here's what I've tried:
[^abc]+(a|b|c)*[^abc]
If I understood your question well, the idea is that a must be before b and b before c if any of them are present. Additionally there might be some d in whatever place.
If that's the case then you can use a regex like this:
^d*(?:a+d*b+d*c+d*)?$
Working demo

if at least one element of array in Perl [duplicate]

This question already has answers here:
How can I check if a Perl array contains a particular value?
(12 answers)
Closed 7 years ago.
Maybe my question is really easy, but I would like to know the best way and efficient one.
Let's we have an array of strings and we want to compare it with another string.
say,
my #array = {"hi","bye","you","shadow", "hi"}
Now I want to check if at least one element of the array equals hi then there is some condition.
May I know your idea about it. I know that within a for loop one could do it easily, but Would you would suggest as a good one?
Something like
my #array = qw (hi bye you shadow hi);
my $hi_count = scalar(grep {$_ eq 'hi'} #array);
print $hi_count;
This will print 2 as there are two words that equal hi.

How to swap two variables in one line in C? [duplicate]

This question already has answers here:
Interchanging values of two variables by xor operator using references or pointers
(2 answers)
Swapping two variable value without using third variable
(31 answers)
Closed 9 years ago.
I want to know that is there any other way of swapping 2 numbers in one line and of course without 3rd variable.
I know one way of doing this:
b=a+b-(a=b)
or
a=a+b-(b=a)
both are same(approximately). If you know then please help me out.
The frequently cited classic answer that you are probably looking for is:
a^=b^=a^=b;
But, it is technically wrong, because it changes the same variable more than once before a sequence point.
Use bit twiddling in C. Following swap two variables:
if (a != b) {
a ^= b ^= a ^= b;
}

Resources