From: us on
"Enrique Gil" <gile(a)msoe.edu> wrote in message <i022f4$1pd$1(a)fred.mathworks.com>...
> "Andy " <theorigamist(a)gmail.com> wrote in message <hvvv30$eb0$1(a)fred.mathworks.com>...
> > While you're at it, instead of having ten different variables, have one array of variables AM(1), AM(2), etc. Write your algorithm as
> >
> > function output = myalgorithm(AMn)
> > ...
> > end
> >
> > Then:
> >
> > for ix = 1:10
> > output(ix) = myalgorithm(AM(ix));
> > end
>
>
> Hey Andy,
>
> Thanks for your help. I am actually still struggling a bit with the syntax. Let me give you a simple example from my code and see how you would implement this. There are much much larger algorithms that I must apply, but for simplicty I'll just use applying a filter. First of all I need to load .mat file which contains all the variables. Each of these variables contains a different sized matrix. I must then design my low-pass filter (already designed) and apply it to each of the variables. However, I need to also create a new variable which contains the filtered version for each of the original variables. For instance, the original is AM_1 and I need to create AM_filt_1. Note that this is just one of the "algorithms" within my m-file and a few other ones must be applied afterwards without user input such as interpolations, curve fittings, etc. I guess, I'm just not sure where

> to place the algorithms given I use a function as you suggested before.
>
> Thank you so much for your help!

well... CSSMers see a lot of words but not the (promised) ...example from my code...

us
From: Andy on
"Enrique Gil" <gile(a)msoe.edu> wrote in message <i022f4$1pd$1(a)fred.mathworks.com>...
> "Andy " <theorigamist(a)gmail.com> wrote in message <hvvv30$eb0$1(a)fred.mathworks.com>...
> > While you're at it, instead of having ten different variables, have one array of variables AM(1), AM(2), etc. Write your algorithm as
> >
> > function output = myalgorithm(AMn)
> > ...
> > end
> >
> > Then:
> >
> > for ix = 1:10
> > output(ix) = myalgorithm(AM(ix));
> > end
>
>
> Hey Andy,
>
> Thanks for your help. I am actually still struggling a bit with the syntax. Let me give you a simple example from my code and see how you would implement this. There are much much larger algorithms that I must apply, but for simplicty I'll just use applying a filter. First of all I need to load .mat file which contains all the variables. Each of these variables contains a different sized matrix. I must then design my low-pass filter (already designed) and apply it to each of the variables. However, I need to also create a new variable which contains the filtered version for each of the original variables. For instance, the original is AM_1 and I need to create AM_filt_1. Note that this is just one of the "algorithms" within my m-file and a few other ones must be applied afterwards without user input such as interpolations, curve fittings, etc. I guess, I'm just not sure where

> to place the algorithms given I use a function as you suggested before.
>
> Thank you so much for your help!


% have this as a subfunction or as a separate m-file:
function output = myfilter(input)
% your filter goes here
end

In your main code, stop using AM_1, AM_2, etc. If these are arrays of different sizes, then store them in a cell array: AM{1} = AM_1, AM{2} = AM_2, etc. Store the filtered output in a cell array as well. Replace the code I gave earlier with:

for ix = 1:10
AM_filt{ix} = myfilter(AM{ix});
end

In MATLAB, it is almost never a good idea to have multiple variables named name_1, name_2, name_3, etc. Whenever you do this, it is probably better to put all of these variables together in an array or cell array.
From: dpb on
Andy wrote:
....

>> ... However, I need to also create a new variable which
>> contains the filtered version for each of the original variables. For
>> instance, the original is AM_1 and I need to create AM_filt_1. ...
>
> % have this as a subfunction or as a separate m-file:
> function output = myfilter(input)
> % your filter goes here
> end
>
> In your main code, stop using AM_1, AM_2, etc. If these are arrays of
> different sizes, then store them in a cell array: AM{1} = AM_1, AM{2} =
> AM_2, etc. Store the filtered output in a cell array as well. Replace
> the code I gave earlier with:
>
> for ix = 1:10
> AM_filt{ix} = myfilter(AM{ix});
> end
>
> In MATLAB, it is almost never a good idea to have multiple variables
> named name_1, name_2, name_3, etc. Whenever you do this, it is probably
> better to put all of these variables together in an array or cell array.

And I'll reiterate to go read the FAQ to which I posted a URL about or
near the first response to your original query (you being OP, not Andy).

--
From: someone on
"Enrique Gil" <gile(a)msoe.edu> wrote in message <i022f4$1pd$1(a)fred.mathworks.com>...
> "Andy " <theorigamist(a)gmail.com> wrote in message <hvvv30$eb0$1(a)fred.mathworks.com>...
> > While you're at it, instead of having ten different variables, have one array of variables AM(1), AM(2), etc. Write your algorithm as
> >
> > function output = myalgorithm(AMn)
> > ...
> > end
> >
> > Then:
> >
> > for ix = 1:10
> > output(ix) = myalgorithm(AM(ix));
> > end
>
>
> Hey Andy,
>
> Thanks for your help. I am actually still struggling a bit with the syntax. Let me give you a simple example from my code and see how you would implement this. There are much much larger algorithms that I must apply, but for simplicty I'll just use applying a filter. First of all I need to load .mat file which contains all the variables. Each of these variables contains a different sized matrix. I must then design my low-pass filter (already designed) and apply it to each of the variables. However, I need to also create a new variable which contains the filtered version for each of the original variables. For instance, the original is AM_1 and I need to create AM_filt_1. Note that this is just one of the "algorithms" within my m-file and a few other ones must be applied afterwards without user input such as interpolations, curve fittings, etc. I guess, I'm just not sure where

> to place the algorithms given I use a function as you suggested before.
>
> Thank you so much for your help!

You REALLY need to read & understand the answer to Q4.6 of the MATLAB FAQ at:

http://matlabwiki.mathworks.com/MATLAB_FAQ

as dbp suggested.