I am new to programming and was wondering how one would use text to input indexes for a matrix.
For example: I have this:
charr1 = ':,:,1,1,1,1,1,1';
XX = GridDo(XXInd);
and I want my output to use the indexing of charr1 to look like this:
XX = GridDo(:,:,1,1,1,1,1,1);
So that I can further automate my code.

 채택된 답변

madhan ravi
madhan ravi 2020년 6월 19일

0 개 추천

charr1 = ':,:,1,1,1,1,1,1';
ix1 = regexp(charr1, '\,','split');
ix2 = str2double(ix1);
ix1(~isnan(ix2)) = num2cell(ix2(~isnan(ix2)));
XX = GridDo(ix1{:})

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Matrix Indexing에 대해 자세히 알아보기

질문:

2020년 6월 19일

댓글:

2020년 6월 19일

Community Treasure Hunt

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

Start Hunting!

Translated by