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:
subplot with generated plot m-files?

Subject: subplot with generated plot m-files?

From: Mike Giordano

Date: 29 Jul, 2009 20:38:03

Message: 1 of 2

I looked at the help for subplot but couldn't figure out a way to do this...

I have a m-file that I had matlab generate from a plot I created. It has 3 lines on it and the input is:
"function createfigure(X1, YMatrix1)
%CREATEFIGURE(X1,YMATRIX1)
% X1: vector of x data
% YMATRIX1: matrix of y data
"

I want to create a 4x3 subplot so I can have 12 plots on 1 page but if I write something like: subplot(4,3,1) = createfigure(....) I get a "too many output arguments" error.

Is there any easy way to do this?

Thanks in advance.

Subject: subplot with generated plot m-files?

From: Dave Brackett

Date: 29 Jul, 2009 21:36:01

Message: 2 of 2

"Mike Giordano" <sakar321@gmail.com> wrote in message <h4qbvb$al3$1@fred.mathworks.com>...
> I looked at the help for subplot but couldn't figure out a way to do this...
>
> I have a m-file that I had matlab generate from a plot I created. It has 3 lines on it and the input is:
> "function createfigure(X1, YMatrix1)
> %CREATEFIGURE(X1,YMATRIX1)
> % X1: vector of x data
> % YMATRIX1: matrix of y data
> "
>
> I want to create a 4x3 subplot so I can have 12 plots on 1 page but if I write something like: subplot(4,3,1) = createfigure(....) I get a "too many output arguments" error.
>
> Is there any easy way to do this?
>
> Thanks in advance.

I'm not sure why you would want to do it this way but the reason you are getting that error is because subplot(4,3,1) = createfigure(...) doesn't actually make sense. Your function 'createfigure' actually doesn't currently have any outputs. If it did, createfigure would have them included in the first line of the function e.g. function [output1 output2]=createfigure(...). When calling a function the variable to the left of the = is the output.

Wouldn't it just be easier to plot directly instead of calling the autogenerated functions? e.g.
X1=[1:10] % example data
Y1=x.^2

figure
for i=1:12
subplot(4,3,i)
plot(X1,Y1)
end

Anyway, if you need to call a function in this way to create a plot you could use something like this:

X1=[1:10] % example data
Y1=x.^2

h=figure; % creates a handle to the figure
for i=1:12
createfigure1(h,i,X1, Y1)
end

You would need to edit the createfigure function so that it accepts these new inputs and reflects the example below:

function createfigure1(h,i,X1, Y1)
%CREATEFIGURE1(X1,Y1)
% X1: vector of x data
% Y1: vector of y data

% Auto-generated by MATLAB on 29-Jul-2009 22:19:34

% Create figure
% figure1 = figure('PaperSize',[20.98 29.68]); This is no longer needed

% Create axes
axes('Parent',h);
box('on');
hold('all');

% Create plot
subplot(4,3,i)
plot(X1,Y1);



Hope that helps.

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