Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

plot with structfun

21 views
Skip to first unread message

Kai

unread,
Jun 5, 2010, 6:13:04 AM6/5/10
to
I like to plot my struct with the following code:

structfun(@plot,Data)

Data is a struct with different trials:
eg.
size(Data.trial1)=158 1

I like to change the color as in the following code
plot(Data.trial1,'r')

Can everybody help me?

Best,
Kai

sscnekro

unread,
Jun 5, 2010, 7:38:03 AM6/5/10
to
> I like to plot
> Can everybody help me?

I like .. the way you write. Try this:
create an m-file named makeitred, containing
function sth = makeitred(x)
sth = plot(x,'r')

Then write to command window:
a = [1,2,3,4,5]; b = [3,4,6,6,4,45,446,4,34]; c = [2,454,555,5]; S.a = a; S.b = b; S.c = c;
LHS = structfun(@makeitred,S)

I suppose you will like to add a few more commands to the makeitred function, as e.g. save / export your figure, formatting, labeling, etc. You can also specify the function with more than one input. Come with more questions if you get stuck again. Best of luck.

Wayne King

unread,
Jun 5, 2010, 10:38:03 AM6/5/10
to
"Kai " <sihin...@gmx.de> wrote in message <hud7vg$r43$1...@fred.mathworks.com>...

Hi Kai, perhaps you want something like:

test = struct('data1',randn(158,1), 'data2',cos(2*pi*(1/2)*(0:99)));
axes('NextPlot','add');
A = structfun(@plot,test,'UniformOutput',false);
set(A.data1,'color','r');

Hope that helps,
Wayne

Walter Roberson

unread,
Jun 5, 2010, 12:27:05 PM6/5/10
to
Kai wrote:
> I like to plot my struct with the following code:
>
> structfun(@plot,Data)
>
> Data is a struct with different trials:
> eg.
> size(Data.trial1)=158 1
>
> I like to change the color as in the following code
> plot(Data.trial1,'r')

linehandles = structfun(@plot,Data);
[tf, idx] = strmatch('trial1', fieldnames(Data));
set(linehandles(idx), 'Color', 'r');

Steven Lord

unread,
Jun 6, 2010, 11:21:44 PM6/6/10
to

"Kai " <sihin...@gmx.de> wrote in message
news:hud7vg$r43$1...@fred.mathworks.com...

structfun(@(z) plot(z, 'r'), Data)

--
Steve Lord
sl...@mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
To contact Technical Support use the Contact Us link on
http://www.mathworks.com


0 new messages