Using different strings for same operations
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
MiauMiau
am 28 Jan. 2017
Beantwortet: Jan
am 28 Jan. 2017
Hi
I have in my code many lines which are something like this:
onset_stim112 = reshape(onset_stim112(numStim-rem+1:end),[rem,1]);
onset_stim113 = reshape(onset_stim113(numStim-rem+1:end),[rem,1]);
onset_stim114 = reshape(onset_stim114(numStim-rem+1:end),[rem,1]);
onset_stim115 = reshape(onset_stim115(numStim-rem+1:end),[rem,1]);
As you can see, the same operation is performed on the right, but the names of the doubles on the left are slightly different. I have this repeatedly in my code - is there any way to do this short and more efficient? I was thinking about defining a string-array at the beginning and looping then through the names of the different stimulation variables, but I think looping is also not the most efficient way... Many thanks..
0 Kommentare
Akzeptierte Antwort
Weitere Antworten (1)
Jan
am 28 Jan. 2017
This is a V(ery)FAQ. See also: https://www.mathworks.com/matlabcentral/answers/304528-tutorial-why-variables-should-not-be-named-dynamically-eval
0 Kommentare
Siehe auch
Kategorien
Mehr zu Characters and Strings finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!