Inserting a variable in a name of an object

2 views (last 30 days)
Im using this code
C = 16
Sample = S1
S1 = Array1; %Sample1
S2 = Array2; %Sample2
S3 = Array3; %Sample3
S4 = Array4; %Sample4
column16_1 = cellfun(@(m) m(:, C), Sample, 'UniformOutput', false);
Can i change the name of the created array "column16_1" in this way:
columnC_Sample
So what I want is that, if I change the value of "C" and "Sample", I want matlab to automatically create a new name for the new created array.
I hope I made my problem clear enough.
Thanks for the help!

Accepted Answer

Guillaume
Guillaume on 1 Oct 2015
It's possible, but DON'T. You'll be going down a path that is very inefficient, hard to debug, hard to edit, and simply prone to errors.
The proper way is to use a cell array indexed by column number and sample number. (or if all the columns are the same size, simply use plain multidimensional array). Similarly your sample arrays should be stored in a cell array, not in numbered variables:
Sample{1} = Array1; Sample{2} = Array2; Sample{3} = Array3; Sample{4} = Array4;
column{C, S} = cellfun(@(m) m(:, C), Sample{S}, 'UniformOutput', false);
See the FAQ for why it's a bad idea to number variables.

More Answers (0)

Categories

Find more on Multidimensional Arrays in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!