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:
help with input

Subject: help with input

From: Feixiong

Date: 9 Apr, 2010 11:19:05

Message: 1 of 2

I have a program written in Matlab. Actually, in the beginning, I did not realize it would be a problem. With the progress of the project, there are more and more small parts(functions), and also the variables. Finally, I collect all the results of variables from other functions and use them as input to another function. Surprisingly, there 35 different input. In addition, Global variables and nested functions are already making the program complex.

All of a sudden, I found the program was poorly written.I am wondering how to manage and orginize the variables and function.

Subject: help with input

From: Rob Campbell

Date: 9 Apr, 2010 13:15:33

Message: 2 of 2

"Feixiong " <f.liao@tue.nl> wrote in message <hpn2f9$r23$1@fred.mathworks.com>...
> I have a program written in Matlab. Actually, in the beginning, I did not realize it would be a problem. With the progress of the project, there are more and more small parts(functions), and also the variables. Finally, I collect all the results of variables from other functions and use them as input to another function. Surprisingly, there 35 different input. In addition, Global variables and nested functions are already making the program complex.
>
> All of a sudden, I found the program was poorly written.I am wondering how to manage and orginize the variables and function.

I think you want to use a structure rather than individual variables. Passing a structure around will make your code easier to handle.

If I were you, I'd look around on the FEX and see how complicated projects are laid out. Then go back to your code and re-design yours from the ground up. You need to plan it from the beginning this time: A while ago I inherited some over-complicated code which was laid out in the way yours appears to be. It was a complete nightmare and so I re-wrote everything. There were multiple problems with it: too many input variables, lack of clarity, lots of redundant code, etc.

If you e-mail me what your stuff looks like then I may be able to give detailed suggestions (if I have time!)

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