Got Questions? Get Answers.
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:
Access variables inside a comment line for m-file publishing

Subject: Access variables inside a comment line for m-file publishing

From: jrenfree

Date: 30 Sep, 2010 19:11:15

Message: 1 of 3

Hi all,

I'm trying to publish an m-file so that I can easily create a report
after collecting some data.

One question I have is if it's possible to access a variable inside a
comment line to help me create a Section Title. For example, let's
say I want the title of my section to be "18 kHz data." I don't want
to have to hard code that into the cell header because the frequencies
will be changing. Is that possible?

Here's an example of what I'd basically do in the m-file code:

---------What it should be------------
%% 18 kHz data
% Plot for 18 kHz data

--------What I'd like so as to avoid hardcoding-------------
%% sprintf('%d kHz data', freq(i))
% Plot for sprintf('%d kHz data', freq(i))

but I realize this won't work because you can't access variables
inside comment lines. Any ideas?

Thanks.

Subject: Access variables inside a comment line for m-file publishing

From: Diego

Date: 30 Sep, 2010 19:27:04

Message: 2 of 3

jrenfree <jrenfree@gmail.com> wrote in message <9b6bd872-47e6-4332-a9d3-81bb4999dff2@h40g2000pro.googlegroups.com>...
> Hi all,
>
> I'm trying to publish an m-file so that I can easily create a report
> after collecting some data.
>
> One question I have is if it's possible to access a variable inside a
> comment line to help me create a Section Title. For example, let's
> say I want the title of my section to be "18 kHz data." I don't want
> to have to hard code that into the cell header because the frequencies
> will be changing. Is that possible?
>
> Here's an example of what I'd basically do in the m-file code:
>
> ---------What it should be------------
> %% 18 kHz data
> % Plot for 18 kHz data
>
> --------What I'd like so as to avoid hardcoding-------------
> %% sprintf('%d kHz data', freq(i))
> % Plot for sprintf('%d kHz data', freq(i))
>
> but I realize this won't work because you can't access variables
> inside comment lines. Any ideas?
>
> Thanks.

I don't think it's possible in a .m file.
If you are using a GUI you can use a static text field and use the function set.
Exemple: set(handles.freq, 'String', '18 kHz');

Subject: Access variables inside a comment line for m-file publishing

From: jrenfree

Date: 30 Sep, 2010 19:34:48

Message: 3 of 3

On Sep 30, 12:27 pm, "Diego " <dcamp...@lncc.br> wrote:
> jrenfree <jrenf...@gmail.com> wrote in message <9b6bd872-47e6-4332-a9d3-81bb4999d...@h40g2000pro.googlegroups.com>...
> > Hi all,
>
> > I'm trying to publish an m-file so that I can easily create a report
> > after collecting some data.
>
> > One question I have is if it's possible to access a variable inside a
> > comment line to help me create a Section Title.  For example, let's
> > say I want the title of my section to be "18 kHz data."  I don't want
> > to have to hard code that into the cell header because the frequencies
> > will be changing.  Is that possible?
>
> > Here's an example of what I'd basically do in the m-file code:
>
> > ---------What it should be------------
> > %% 18 kHz data
> > % Plot for 18 kHz data
>
> > --------What I'd like so as to avoid hardcoding-------------
> > %% sprintf('%d kHz data', freq(i))
> > % Plot for sprintf('%d kHz data', freq(i))
>
> > but I realize this won't work because you can't access variables
> > inside comment lines.  Any ideas?
>
> > Thanks.
>
> I don't think it's possible in a .m file.
> If you are using a GUI you can use a static text field and use the function set.
> Exemple: set(handles.freq, 'String', '18 kHz');

That's what I'm afraid of, and I don't know if making a GUI is a
viable option for me.

I'd be surprised if Matlab didn't let you somehow create section
titles from variables instead of having to hard code every title.
Seems extremely limiting.

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