MATLAB Answers

0

Why this not works..?

Asked by Lalit Patil on 21 Dec 2012
n = 10;
for p = 1:n
      lal(p)
end
function [] = lal(p)

.

.

.

This method doesn't work.. Why..?

  0 Comments

Products

No products are associated with this question.

1 Answer

Answer by Walter Roberson
on 21 Dec 2012
 Accepted answer

What does not work about it? What error message is given?

One thing I notice is that in the code you show, if that is the entire code, then you are attempting to define a function inside a script. You need to convert the first part to a function. For example,

function testloop
  n = 10;
  for p = 1 : n
    lal(p)
  end
function [] = lal(p)
  ...

  4 Comments

What happened when you tried?

 d = dir('.');
 n = length(d)-2;
 for imageNumber = 1:n
 myFunction(imageNumber)
 end

It works now..

Problem get solved..

Then officially mark it as solved. Looks just like what Walter said except that the function name is different.


Join the 15-year community celebration.

Play games and win prizes!

Learn more
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

MATLAB Academy

New to MATLAB?

Learn MATLAB today!