MATLAB Answers

Convert Cell to variable name array

65 views (last 30 days)
joms
joms on 17 May 2019
Commented: Stephen Cobeldick on 19 May 2019
How can i use cell text as variable name input?
I want to use string variables "A" as variable name to output"B".
A={'sample1' 'sample 2' 'sample3'}
like this:
[B]=[sample1, sample2, sample3]
please suggest code made for 2013 matlab version.
Thanks for your help!
  6 Comments
joms
joms on 17 May 2019
my code is just simple label order changer not be used for future troubleshooting. there are 100 plus variables so i need it even it work inefficiently

Sign in to comment.

Accepted Answer

madhan ravi
madhan ravi on 17 May 2019
A={'sample1' 'sample2' 'sample3'} ;
a = array2table(rand(3)); % an example
a.Properties.VariableNames=A
  7 Comments
Stephen Cobeldick
Stephen Cobeldick on 19 May 2019
Rather than this complex and inflexible code:
sample1=patie2(:,1)
sample2=patie2(:,2)
sample3=patie2(:,3)
sample4=patie2(:,4)
patie = table(time,sample3,sample4,sample2,sample3);
just use array2table. In fact it seems like most of your code could be replaced by array2table and a few table operations.

Sign in to comment.

More Answers (0)

Products


Release

R2013b

Community Treasure Hunt

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

Start Hunting!