0

On the MATLAB commandline, I can recall the previous command with the UP arrow. However, if I already have typed something and then hit UP arrow, only commands beginning with what I already typed will show up. This is mostly useful, and very annoying at the same time. Often what I want is this:

>> longVariable

longVariable =

     1     2
     3     4

and immediately afterwards I want to type something like

size(<thatLastThing>)

which in bash I can just do by typing ALT+. (beautiful). I can't get that behavior in MATLAB though... unless you can help me out?

PS: I am aware that I could just hit UP arrow, POS1, "size(" etc - it's what I am doing now, but it is very counter intuitive to me.

PPS: Today I discovered that my desired behavior is correctly implemented in octave - which is very nice for octave, but I'd really love to have this in Matlab...

0

Basically, ans is a "variable" that Matlab creates when you type any command that returns output without specifying output argument. Read more here

So if you write something like this:

[1 2 3];
ans

the result will be

[1 2 3]

and if you write

size(ans)

you'll get

[1 3]

hope it helps!

| improve this answer | |
  • I tried that before, but in my above example, size(ans) gives me 1 2 when it should be 2 2. – Paul Sep 10 '19 at 11:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.