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:
Pass string to function to increment figure number & figure title

Subject: Pass string to function to increment figure number & figure title

From: Kenneth

Date: 12 Sep, 2013 16:32:06

Message: 1 of 3

Dear Colleagues,

I have written a simple function which calculates the tangent to a curve at a single point (x1, y1) and in addition using the central difference method, taking points in front and behind the point of interest for comparison against noisy data (due to using the diff function)

As I will be calling this function many times for a large set of input files, I would like to add two additional inputs to the function, a number, 1,...,n which increments the command

figure( insert number here)

and also a string - i.e. device number which updates the title of the figure

h=title('Results for INPUT DEVICE NUMBER HERE')

I would appreciate any help and thank everyone in advance for theory time and suggestions. Apologies if this is trivial but my exposure to MATLAB is limited.

MATLAB R2012B, Windows 7.

The code is as follows:

__________________________________________________________

function [Central_diff, Exact_point] = Tangent(location, Cdata , Vdata)

%% y = mx + c -- Cdata = df*Vdata + C

% Simple central difference approach
y2 = Cdata(location+1);
y1 = Cdata(location-1);
x2 = Vdata(location+1);
x1 = Vdata(location-1);
y_x = (y2 - y1)/(x2-x1);
m1 = y_x;
c = Cdata(location) - m1*Vdata(location);
Central_diff = m1*Vdata+c;

% Exact point tangent
y = Cdata;
x = Vdata;
dy = diff(y);
dy = [dy dy(end)];
dx = diff(x);
dx = [dx dx(end)];
df = dy./dx;
m2 = df(location); % gradient at specified location
c = y(location) - x(location)*m2; % y intercept

Exact_point = m2*x + c;

%% Plot figures automatically each time the function is called

figure(1) %replace with string to increment figures per graph generation
set(gcf, 'units','normalized','outerposition',[0 0 1 1]); % Maximize figure
SetPlotFont('Times',18); %additional *.m file which must be included
axis auto
set(gca, 'XTick',[-8 -7 -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6])
%axis([-8 6 0 10e-5])
hold all
plot(Vdata, Cdata);
plot(Vdata, Central_diff,'-o');
plot(Vdata, Exact_point,'-x');
grid on
h=title('C-V Curve with Central Difference & Point Tangent INSERT WAFER STRING ');
ylabel('Capacitance')
xlabel('Gate Voltage [V]');
legend('C-V Curve','Central Difference Tangent', 'Exact Tangent')

__________________________________________________________________

Subject: Pass string to function to increment figure number & figure title

From: dpb

Date: 12 Sep, 2013 17:41:02

Message: 2 of 3

On 9/12/2013 11:32 AM, Kenneth wrote:
...

> ... I would like to add two additional inputs to the function, a
> number, 1,...,n which increments the command
>
> figure( insert number here)
>
> and also a string - i.e. device number which updates the title of the
> figure
>
> h=title('Results for INPUT DEVICE NUMBER HERE')
>
> I would appreciate any help and thank everyone in advance for theory
> time and suggestions. Apologies if this is trivial but my exposure to
> MATLAB is limited.
...

> function [Central_diff, Exact_point] = Tangent(location, Cdata , Vdata)
...

function [C,E] = Tangent(location,Cdata,Vdata, fignum, device)
   ...
   figure(fignum)
   % Actually, rarely is there a need for the number itself; simply use

   figure

   % will increment to the next available number automagically so
   % could do w/o the fignum argument in all likelihood.
   ...

   t=['C-V Curve with Central Difference & Point Tangent ' num2str(device)];
   title(t)
   ...

That's all there is to it...

--

Subject: Pass string to function to increment figure number & figure title

From: Kenneth

Date: 14 Sep, 2013 17:23:09

Message: 3 of 3

dpb <none@non.net> wrote in message <l0subu$tgg$1@speranza.aioe.org>...
> On 9/12/2013 11:32 AM, Kenneth wrote:
> ...
>
> > ... I would like to add two additional inputs to the function, a
> > number, 1,...,n which increments the command
> >
> > figure( insert number here)
> >
> > and also a string - i.e. device number which updates the title of the
> > figure
> >
> > h=title('Results for INPUT DEVICE NUMBER HERE')
> >
> > I would appreciate any help and thank everyone in advance for theory
> > time and suggestions. Apologies if this is trivial but my exposure to
> > MATLAB is limited.
> ...
>
> > function [Central_diff, Exact_point] = Tangent(location, Cdata , Vdata)
> ...
>
> function [C,E] = Tangent(location,Cdata,Vdata, fignum, device)
> ...
> figure(fignum)
> % Actually, rarely is there a need for the number itself; simply use
>
> figure
>
> % will increment to the next available number automagically so
> % could do w/o the fignum argument in all likelihood.
> ...
>
> t=['C-V Curve with Central Difference & Point Tangent ' num2str(device)];
> title(t)
> ...
>
> That's all there is to it...
>
> --

Hi,

That's great thank you very much!

Tags for 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