필터 지우기
필터 지우기

Inserting a variable in a name of an object

조회 수: 1 (최근 30일)
Royvg94
Royvg94 2015년 10월 1일
답변: Guillaume 2015년 10월 1일
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!

채택된 답변

Guillaume
Guillaume 2015년 10월 1일
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.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Multidimensional Arrays에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by