0

I am trying to access the following vector

size(start:step-size:end)

to determine the amount of entries that are created (on the fly). If I try to access the entries of

size(start:step-size:end)(2)

I get the following error :

Error: ()-indexing must appear last in an index expression.

However, if I first assign it to a variable, and then access the variable, I do not get the error :

a = size(start:step-size:end);
N = a(2)

Can't I accomplish this without having to store the vector created by the size function ?

imranal
  • 656
  • 12
  • 35
  • It's possible, but requires a hacky way around. See the duplicate. – Adriaan Nov 06 '15 at 20:22
  • 1
    This is possible in Octave, but not in MATLAB. You unfortunately **must** save the results to an intermediate variable before slicing / indexing into them. As @Adriaan noted, there is a hack, but it requires more code than its worth, and it's hard to read. What's the big deal about keeping an extra variable around? Are you concerned about memory issues? Did you profile your code before wanting to do something like this? Do some research and debugging before attempting to "optimize" your code. Minor Note: `size` is a function in MATLAB. Don't shadow the function with a variable. – rayryeng Nov 06 '15 at 20:57

0 Answers0