Info
이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.
I don't want to repeat these , I want to use a loop for it
조회 수: 1 (최근 30일)
이전 댓글 표시
I don't want to repeat these all time , I want to use a loop for it instead of copy and paste it all time ?
Can I just use a ( for ) for it ??????
KG1=zeros (28,28);
KG2=zeros (28,28);
KG3=zeros (28,28);
KG4=zeros (28,28);
KG5=zeros (28,28);
KG6=zeros (28,28);
KG7=zeros (28,28);
KG8=zeros (28,28);
KG9=zeros (28,28);
KG10=zeros (28,28);
댓글 수: 1
Stephen23
2019년 10월 18일
Numbering variables is a sign that you are doing something wrong.
Copy-and-pasting code is a sign that you are doing something wrong.
You can easily avoid both of these issues by using indexing. Indexing is simple, neat, easy to debug, and very efficient (unlike what you are trying to do).
답변 (1개)
Kevin Phung
2019년 10월 17일
편집: Kevin Phung
2019년 10월 17일
perhaps instead of defining 10 variables or dynamically creating them in a for loop, you can store each matrix of zeros as a cell array.
KG = {zeros(28,28)};
KG = repmat(KG,10,1);
% now you can call out each cell array like so:
KG{1};
KG{2};
KG{3};
%etc...
댓글 수: 1
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!