Is there a quick way to create a cell array of strings where strings represent workspace variables?

조회 수: 1 (최근 30일)
I want to create a cell array of strings, where the strings represent workspace variables. Suppose I have a,bb,ccc,dddd ... z26, and so on as variables in the workspace. How can I create a cell array
vars = {... 'a' 'bb' 'ccc' . . . . 'z26' };
I have tried using who with asterix to list variables, or copying in excel and inserting columns of inverted quotations, etc. Any help greatly appreciated!

채택된 답변

Stephen23
Stephen23 2015년 3월 18일
편집: Stephen23 2015년 3월 18일
If you read the documentation for whos then you will find out that you can use wildcard matches like this:
whos('a*')
which matches all variables starting with the letter 'a'. To get a cell array of names without using a loop:
N = whos('a*');
N = {N.name};
  댓글 수: 1
Aniket Vagha
Aniket Vagha 2015년 3월 18일
Thank you both!
I realized I can put multiple wildcards too: N = whos('a*', 'b*') etc.
This helps a lot. Thanks again!

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Characters and Strings에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by