Effacer les filtres
Effacer les filtres

Inserting a variable in a name of an object

1 vue (au cours des 30 derniers jours)
Royvg94
Royvg94 le 1 Oct 2015
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!

Réponse acceptée

Guillaume
Guillaume le 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.

Plus de réponses (0)

Catégories

En savoir plus sur Multidimensional Arrays dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by