Variable pre-definition
7 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
tomas
am 24 Aug. 2011
Beantwortet: bharat suthar
am 23 Mai 2020
Hello,
how can I pre-define list of variables (e.g. var_1,var_2,...,var_n) that have the same content, for example zeros(100). I thought [var_1,var_2,...var_n]=[zeros(100),zeros(100),...,zeros(100)]; could work, but I was wrong. Any idea is appreciated.
Thank you very much,
Tom
0 Kommentare
Akzeptierte Antwort
Amanda Galtman
am 24 Aug. 2011
Try using the deal function:
[var_1, var_2, var_3] = deal(zeros(100));
HTH, Amanda
2 Kommentare
Jan
am 24 Aug. 2011
This is correct, but not optimal for pre-allocation: After DEAL, the variables use shared data copies, which point to teh same memory. If you write to these variables, the sharing link must be released at first. Therefore a direct "var_1=zeros(100); var_2=zeros(100)" is slightly faster. But if it concerns 3 or 50 variables only, this delay can be neglected.
Weitere Antworten (1)
bharat suthar
am 23 Mai 2020
Which of the following is a pre-defined variable in Matlab?
0 Kommentare
Siehe auch
Kategorien
Mehr zu Logical 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!