Prev: pattern recognition/image analysis
Next: How to fit my data to y=a*exp(-bx) by restricting 0<a<1?
From: Merciadri Luca on 1 Apr 2010 14:46 -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hi. I have a function, say, myfunction, which takes some parameters, and output some variables, i.e. it is called using [var1 var2 ... varn] = myfunction(param1, param2, ..., paramn). The problem is that I only want to keep varn in memory once the function has been executed. How can I achieve this? Thanks. - -- Merciadri Luca See http://www.student.montefiore.ulg.ac.be/~merciadri/ - -- Where there's a will, there's a way. -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (GNU/Linux) Comment: Processed by Mailcrypt 3.5.8 <http://mailcrypt.sourceforge.net/> iEYEARECAAYFAku06fsACgkQM0LLzLt8MhxCugCfdsw70jFmmnysIix6aPQa02O3 E9wAn3LyfPAipG8wOue4PR4f72RgaLWZ =W1jw -----END PGP SIGNATURE-----
From: Matt Fig on 1 Apr 2010 14:58 % Data A = magic(3); % Engines [I,I] = sort(A(:)) % or if your MATLAB is new enough: [~,I] = sort(A(:))
From: Jan Simon on 1 Apr 2010 15:08 Dear Merciadri Luca! > I have a function, say, myfunction, which takes some parameters, and > output some variables, i.e. it is called using > > [var1 var2 ... varn] = myfunction(param1, param2, ..., paramn). > > The problem is that I only want to keep varn in memory once the > function has been executed. How can I achieve this? Both mentioned methods ([~, ~, .. varn] and [varn, varn, ..varn]) "waste" some memory, although it is occupied temporarily only. Another idea is using an additional input: varn = myfunction(param1, param2, ..., paramn, nOut) And reply just the nOut.th output. If the other parameters are large, it is worth to compare the computing times. If the function is not critical for time, choose the method you like most. Kind regards, Jan
From: Merciadri Luca on 1 Apr 2010 15:09 -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 "Matt Fig" <spamanon(a)yahoo.com> writes: > % Data > A = magic(3); > > % Engines > [I,I] = sort(A(:)) > > % or if your MATLAB is new enough: > > [~,I] = sort(A(:)) Thanks. Nice. As I have an old version (7.0, R14), I need to use your second possibility. However, there is one case where it seems not to work here, as the M-Lint Code Check Report gives me `The value assigned to var1 is never used,' where var1 is actually used. I mean that function myfunction2 sends [var1 var2], but I call it with [var2 var2] = myfunction2(some stuff), where var2 is used later in my code (not in the function, evidently), but not var1. Why do I get this message? Thanks. - -- Merciadri Luca See http://www.student.montefiore.ulg.ac.be/~merciadri/ - -- Working hard or hardly working? -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (GNU/Linux) Comment: Processed by Mailcrypt 3.5.8 <http://mailcrypt.sourceforge.net/> iEYEARECAAYFAku073EACgkQM0LLzLt8Mhx2ZQCfaYo4fV+XT7/HIKJnkSifNoQq UOwAoIaBo9v4yFWljl+dSROV49VcJ1D8 =zl7Y -----END PGP SIGNATURE-----
From: dpb on 1 Apr 2010 15:45 Merciadri Luca wrote: .... > ... M-Lint Code Check Report gives me `The value > assigned to var1 is never used,' where var1 is actually used. I mean that > function myfunction2 sends [var1 var2], but I call it with > > [var2 var2] = myfunction2(some stuff), > where var2 is used later in my code (not in the function, evidently), > but not var1. ... Would have to see actual code to confirm but I'd presume it's caught on to the fact that var1 isn't actually assigned on the output but is declared as an output in the function definition... --
|
Next
|
Last
Pages: 1 2 3 4 Prev: pattern recognition/image analysis Next: How to fit my data to y=a*exp(-bx) by restricting 0<a<1? |