필터 지우기
필터 지우기

Variable pre-definition

조회 수: 5 (최근 30일)
tomas
tomas 2011년 8월 24일
답변: bharat suthar 2020년 5월 23일
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

채택된 답변

Amanda Galtman
Amanda Galtman 2011년 8월 24일
Try using the deal function:
[var_1, var_2, var_3] = deal(zeros(100));
HTH, Amanda
  댓글 수: 2
tomas
tomas 2011년 8월 24일
That's it. Thank you Amanda :-)
Jan
Jan 2011년 8월 24일
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.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

bharat suthar
bharat suthar 2020년 5월 23일
Which of the following is a pre-defined variable in Matlab?

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by