'How to get the position of a returned array from a MATLAB function in one line [duplicate]
When trying to get the position of an item returned by a function in MATLAB, I always need two rows of code.
For example, I currently do this:
testString = 'Hello!';
strSize = size(testString); % returns two dimensions: [1,6]
strSize = strSize(2); % returns one dimension: 6
But, I'd like to do this, as possible in Javascript:
testString = 'Hello!';
strSize = size(testString)(2); % returns one dimension: 6
Is there any trick in MATLAB to get the return of the 'size' function and, in the same row, ask for a specific position in the array?
Thanks, colleagues!
Solution 1:[1]
You can do the following:
[strSize1 strSize2] = size(testString);
Because you only want strSize2, you can also do
[~ strSize] = size(testString)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | BJW |
