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

Looking for "publish" example for a function with input arguments.

1,222 views
Skip to first unread message

Jim Rockford

unread,
Jan 28, 2013, 3:59:30 AM1/28/13
to
I can't seem to find a straightforward example on using the "publish" function when it's a function being published that takes input arguments.

For example, I have the function z = myfunk(x,y)

The simple publish command >> publish('myfunk','doc')
of course doesn't work
because the input arguments x and y aren't known.

What is the syntax for specifying the input arguments x,y to publish this function?

The documentation just says
"Additional code to evaluate during publishing, specified as the comma-separated pair consisting of 'codeToEvaluate' and the string with the corresponding code. Use this option to specify code that does not appear in the MATLAB file, for example to set the value of an input argument for a function being published."

Sorry, but I find this too opaque absent a single clear example showing this syntax.

Thanks for the help.

JR

Loren Shure

unread,
Jan 28, 2013, 11:19:24 AM1/28/13
to

"Jim Rockford" <jim.ro...@gmail.com> wrote in message
news:c52b56c9-ec1f-4476...@googlegroups.com...
I believe you need to make a publish configuration that calls the function
with inputs. But I am not near a MATLAB right now to try it.

--
Loren
http://blogs.mathworks.com/loren/
http://www.mathworks.com/matlabcentral/

Matt Jecha

unread,
May 14, 2013, 12:20:22 AM5/14/13
to
I have been searching for the same answer as to how to implement the options structure or name-value pairs in the publish() function.

I found this solution from the 2008 MATLAB version:
http://www.mathworks.com/support/solutions/en/data/1-97WVV6/?solution=1-97WVV6

Which cites a wrapper function with the following code:
function mypublish(fun,funcall,inputs)

opts.codeToEvaluate=[
inputs, char(10),...
funcall,char(10)];

publish(fun,opts)

web([pwd '\html\' fun '.html'])

used to publish the hypothetical function foo():
function foo(a)
plot(a);
end

For a school project, I am attempting to write an automated script which runs through a lowpass filter generation scheme in a four-level for loop iteration, changing one parameter through several values at each level. In the heart of this for loop, I would like to publish a function I have written that generates the filter and plots its impulse response as a separate file.


Jim Rockford <jim.ro...@gmail.com> wrote in message <c52b56c9-ec1f-4476...@googlegroups.com>...

Steven_Lord

unread,
May 14, 2013, 9:35:06 AM5/14/13
to


"Matt Jecha" <jechamt+...@gmail.com> wrote in message
news:kmse26$jqv$1...@newscl01ah.mathworks.com...
> I have been searching for the same answer as to how to implement the
> options structure or name-value pairs in the publish() function.

http://www.mathworks.com/help/matlab/ref/publish.html

See the third and fourth items in the Examples section of that documentation
page.

*snip*

--
Steve Lord
sl...@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

WASSIM

unread,
Jul 19, 2013, 10:21:13 AM7/19/13
to
"Steven_Lord" <sl...@mathworks.com> wrote in message <kmteia$hr3$1...@newscl01ah.mathworks.com>...
>
>
> "Matt Jecha" <jechamt+...@gmail.com> wrote in message
> news:kmse26$jqv$1...@newscl01ah.mathworks.com...
> > I have been searching for the same answer as to how to implement the
> > options structure or name-value pairs in the publish() function.


when I use this structure to publish a function with input arguments
opts.codeToEvaluate=[
'plotData', char(10),...
'plot_report(plotData)',char(10)];

I got the following error:
Error using evalin
Undefined function or variable 'plotData'

I don't understand why I got this error as I define the variable just before calling the publish function.

And when I try with this simple example it's working:
f.x =0:0.1:10;
f.y = 0:0.5:50;
function_options.codeToEvaluate=[
'f', char(10),...
'test(f)',char(10)];
publish('test',function_options);

function test(f)
figure;
plot (f.x, f.y);
end

is there any size limitation to pass the input arguments to the publish function??

Cedric

unread,
Feb 11, 2014, 7:06:06 PM2/11/14
to
"WASSIM " <mhiri...@gnet.tn> wrote in message <ksbi0p$ei4$1...@newscl01ah.mathworks.com>...
Hi everyone,
I am having the same kind of issue...
Has this ever been resolved?
Also, the link posted above is broken:(http://www.mathworks.com/support/solutions/en/data/1-97WVV6/?solution=1-97WVV6)

My code is the following:
[...]
for d = 1:sizeOfSomething
functionOpts.codeToEvaluate=['fullFileList{d}', char(10),'my_func(fullFileList{d})'];
functionOpts.evalCode = true;
functionOpts.format = 'html';
functionOpts.outputDir = savingPath;
publish('my_func',functionOpts);
end
[...]

Error using ==> evalin
Undefined function or variable 'd'.

The error I am getting is that the "code to be evaluated" does not know 'd'.
Then I tried replacing 'fullFileList{d}' by it's actual string but I get another error (Unexpected MATLAB Operator).

Does anybody knows what is wrong here? Also, what is the purpose of the "newline" in the middle (char(10))?

Thanks

Nicolas Cottaris

unread,
Sep 16, 2014, 2:10:16 PM9/16/14
to
Hello,

After lots of trials and errors I determined that for this to work the arguments struct (say params) must exist in the base workspace.

This can be achieved by adding the following statement:
assignin('base', 'params', params);

right before the following:
options.codeToEvaluate = ['params', char(10), 'foo(params)', char(10)'];
publish(foo', options);

I have only tested this in R2014a.

Best,
Nicolas

Nicolas Cottaris

unread,
Sep 16, 2014, 2:11:15 PM9/16/14
to
0 new messages