Using characters for indexing in 2019b

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{:})

1 件のコメント

Ronald Strong
Ronald Strong 2020 年 6 月 19 日
Awesome, this worked!
Thanks Madhan!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeMatrix Indexing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by