Swap between two sub array of an array
Ältere Kommentare anzeigen
Swap between two sub sequences. Position one and two are selected randomly first and then position three and four. Provided these selections do not overlap then element sequence between position one and two and element sequence between position three and four are swapped.
Example: idx1 = [2 4], idx2 = [7 10], A = [2 5 3 4 7 1 6 9 8 10 11 12] would become Anew=[2 6 9 8 10 7 1 5 3 4 11 12]
Thank you
Akzeptierte Antwort
Weitere Antworten (1)
Amine Ne
am 20 Aug. 2018
5 Kommentare
Stephan
am 20 Aug. 2018
Nice,
but i guess it is a pretty expensive calculation if you use it for local search. I think about TSP for example to use it and how many times it has to be calculated to get a better result...
However, the code is working so far.
Amine Ne
am 20 Aug. 2018
Amine Ne
am 20 Aug. 2018
Stephan
am 21 Aug. 2018
Do you have to write your own algorithm? If not i would suggest to use Global Optimization Toolbox (if you have access to it), since there are possibilities of parallelisation (if you have access to Parallel omputing Toolbox) and the code is optimized by professionals.
If you have or want to write your own code i would suggest to do the following:
I think it would be worthwhile to search the forum and the documentation for vectorization, parallelization and performance enhancement and related topics.
There are numerous contributions (accepted answers) specifically from the MVP contributers (e.g. Walter Roberson, Jan, Stephen Cobeldick, John D'Errico, Star Strider, Guillaume, dpb, KSSV ... and many others) in which people have asked for options on their code to optimize and speed up.
Especially James Tursa (according to his profile) is interested in speed and performance and has certainly given some good hints in his answers.
These are certainly good sources to get suggestions for your project.
Another way (you can do by yourself) is to check and improve your code by using the Profiler feature and the Analyze Code Button. These tools show you where in your code how much time is spent or where you have typical errors. This may provide evidence of improvement.
I suggest you to try these ways and in places where you have questions to come back with a new question here. It's always amazing to see how well some people can deal with Matlab and how much knowledge is available here.
As an example read this link where i asked for the possibilities of improvement from a matlab code. The answer John D'Errico gave me brought me a lot of insight to this topic.
Thats what i can suggest you.
Best regards
Stephan
Amine Ne
am 22 Aug. 2018
Kategorien
Mehr zu Multirate Signal Processing finden Sie in Hilfe-Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!