0

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!

1 Answers1

1

You can do the following:

[strSize1 strSize2] = size(testString);

Because you only want strSize2, you can also do

[~ strSize] = size(testString)
BJW
  • 925
  • 5
  • 15