Prev: Linear algebra question
Next: Simulink Video to GUI
From: Grzegorz Popek on 9 Jul 2010 03:31 Is there a way to choose just a few elements from array returned from function without previously assigning function output to additional variable? Here is short example of what I mean: There is a plot and we retrieve XData from it. Let's say we want to remove one element and add one element at the end. Every time we do this we need to pass it through additional variable. And that's what we would like to avoid. But is there a way? for i = 1 : 10 foo = get(h,'XData'); set(h,'XData',[foo(2:end) i]) drawnow; pause(.1); end
From: Bruno Luong on 9 Jul 2010 04:40 "Grzegorz Popek" <liljoe(a)o2.pl> wrote in message <i16j7p$ojt$1(a)fred.mathworks.com>... > Is there a way to choose just a few elements from array returned from function without previously assigning function output to additional variable? > > Here is short example of what I mean: > There is a plot and we retrieve XData from it. Let's say we want to remove one element and add one element at the end. Every time we do this we need to pass it through additional variable. And that's what we would like to avoid. But is there a way? > > for i = 1 : 10 > foo = get(h,'XData'); > set(h,'XData',[foo(2:end) i]) > drawnow; pause(.1); > end This question is asked many time : currently Matlab can't do cascade indexing with built-in syntax. If you want absolutely avoid intermediate value to create, here is few workaround: 1. Use subsref() function 2. Create your own function to extract the subindex 3. Create your own object class and overload the method subsref But create intermediate variable is still the simplest way. Bruno
From: Grzegorz Popek on 9 Jul 2010 05:13 "Bruno Luong" <b.luong(a)fogale.findmycountry> wrote in message <i16n96$4oi$1(a)fred.mathworks.com>... > This question is asked many time : currently Matlab can't do cascade indexing with built-in syntax. > > If you want absolutely avoid intermediate value to create, here is few workaround: > 1. Use subsref() function > 2. Create your own function to extract the subindex > 3. Create your own object class and overload the method subsref > > But create intermediate variable is still the simplest way. > > Bruno Thank You for the reply. It's not that I wanted to avoid creating this variable at all costs. I simply hoped there is some basic way (that I don't know of) to do this that without additional assignments. Grzegorz
|
Pages: 1 Prev: Linear algebra question Next: Simulink Video to GUI |