Automatically create variations of the same variable?

조회 수: 3 (최근 30일)
Ashton Linney
Ashton Linney 2020년 4월 7일
댓글: Ashton Linney 2020년 4월 7일
I have this code. At the moment there are only three check boxes giving the option for Type 1, 2 and 3. Multiple can be selected at once.
% mat(1 through to 3) = zeros(4,16);
if app.chkType1.Value == 1
mat1 = xlsread('Matrices.xlsx','C3:R6');
end
if app.chkType2.Value == 1
mat2 = xlsread('Matrices.xlsx','C9:R12');
end
if app.chkType3.Value == 1
mat3 = xlsread('Matrices.xlsx','C15:R18');
end
% sum mat(1 through to 3)
How can I write this, so that it automatically assigns numbers to the mat title?
i.e, I could maunually write out:
mat1 = zeros(4,16);
mat2 = zeros(4,16);
mat3 = zeros(4,16);
How can I write this in a single line, such that if I had 100 check boxes rather than 3, I would not have to write out 100 lines of zeros?
Thank you

채택된 답변

Walter Roberson
Walter Roberson 2020년 4월 7일
Do not use separate variables. use a cell array. You can have a table of range entries and loop through a list of check boxes, pulling out the range and xlsread() and assign into the cell array
  댓글 수: 1
Ashton Linney
Ashton Linney 2020년 4월 7일
Thank you, I have managed to achieve it through using cell arrays

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

추가 답변 (0개)

카테고리

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

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by