0

I am calling a function in matlab that returns a array but I seem to have to store it in a variable to index it.

This is what is working:

lol = coeffvalues(f4)
needed_ans = lol(1)

but coming from python I expect something like this :

needed_ans = coeffvalues(f4)(1)

without something like that I cannot pipe values as I imagine, is there a solution

praneeth mendu
  • 369
  • 3
  • 17

1 Answers1

1

you can use getfieldin matlab, this is how you can do it :

getfield(coeffvalues(f4),{1})

there are more options to get that in one lines, but I think getfield is the simplest. This assume that the output of your function is an array, not a cell or structure etc.

on a side note, the behavior you describe in python is reserved in matlab to access cell array elements, for example C{4}(1) will access the 1st element of the 4th cell structure in C....

bla
  • 25,846
  • 10
  • 70
  • 101