フィルターのクリア

Address a variable using the name of another variable

3 ビュー (過去 30 日間)
Philipe
Philipe 2013 年 12 月 4 日
編集済み: Matt J 2013 年 12 月 4 日
Greetings. I`m using Matlab to analyse some of my biology experiments and I`m currently having problems. Since I`m using a lot of strange variables and a lot of data, I`ll summarise my problems in this example:
% create a 1x2 cell with chars
list{1,1}='A';
list{1,2}='B';
%create a simple vector
testA=[1 2 3 4 5 6 7 8 9 10];
%get the mean
mean_testA=mean(testA);
What I want is to be able to use the char in “list” to address testA.
Something like mean_testA=mean(test list{1,1})
Thank you!

採用された回答

Sean de Wolski
Sean de Wolski 2013 年 12 月 4 日
Sounds like you probably want to look into using structures with dynamic fieldnames
Also, in the FAQ:

その他の回答 (1 件)

Matt J
Matt J 2013 年 12 月 4 日
編集済み: Matt J 2013 年 12 月 4 日
It seems to make the most sense to put your actual data in test_list{i}, e.g.,
test_list{1,1}=testA;
Then your command mean_testA=mean(test list{1,1}) will do exactly what you want. You can also do things like
S.A=testA;
S.B=whatever;
testlist=fieldnames(S);
mean_testA = mean(S.(testlist{1}))
mean_testB = mean(S.(testlist{2}))

カテゴリ

Help Center および File ExchangeGet Started with MATLAB についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by