Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Looking for "publish" example for a function with input arguments.

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

From: Jim Rockford

Date: 28 Jan, 2013 08:59:30

Message: 1 of 8

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

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

From: Loren Shure

Date: 28 Jan, 2013 16:19:24

Message: 2 of 8


"Jim Rockford" <jim.rockford1@gmail.com> wrote in message
news:c52b56c9-ec1f-4476-a956-9af54a0c64e4@googlegroups.com...
> 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

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/

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

From: Matt Jecha

Date: 14 May, 2013 04:20:22

Message: 3 of 8

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.rockford1@gmail.com> wrote in message <c52b56c9-ec1f-4476-a956-9af54a0c64e4@googlegroups.com>...
> 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

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

From: Steven_Lord

Date: 14 May, 2013 13:35:06

Message: 4 of 8



"Matt Jecha" <jechamt+mathworks@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
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

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

From: WASSIM

Date: 19 Jul, 2013 14:21:13

Message: 5 of 8

"Steven_Lord" <slord@mathworks.com> wrote in message <kmteia$hr3$1@newscl01ah.mathworks.com>...
>
>
> "Matt Jecha" <jechamt+mathworks@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??

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

From: Cedric

Date: 12 Feb, 2014 00:06:06

Message: 6 of 8

"WASSIM " <mhiriwassim@gnet.tn> wrote in message <ksbi0p$ei4$1@newscl01ah.mathworks.com>...
> "Steven_Lord" <slord@mathworks.com> wrote in message <kmteia$hr3$1@newscl01ah.mathworks.com>...
> >
> >
> > "Matt Jecha" <jechamt+mathworks@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??

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

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

From: Nicolas Cottaris

Date: 16 Sep, 2014 18:10:16

Message: 7 of 8

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

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

From: Nicolas Cottaris

Date: 16 Sep, 2014 18:11:15

Message: 8 of 8

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

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us