Passing string as function argument
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
Hey. I am having a little difficulty with processing a large batch of data. I have approximately 1700 independent data points in my workspace. I would like to scale each of those with respect to a factor. Each variable is 1024*2 with the name something like spec100_0.
If I use a = who to list all variables, I can access each string by a{i,1} = (variablename)
Is there a way to use a{i,1} with a counter to pass all variables through a function? At the moment when i do that I only get the string but not the associated variable.
Thanks for any help.
Max
0 Commenti
Risposta accettata
David Young
il 24 Nov 2011
It's a bad idea to store your data in 1700 different variables: you'll find it is inefficient, and you already see how awkward it makes your code. It's far far better to use an array with 1700 elements. See this article.
10 Commenti
Sven
il 24 Nov 2011
Need to scale by two different amounts for the two columns? Also easy:
[myData(:,1,:)*5 myData(:,2,:)*10]
There's also a slightly cleaner version with a little more advanced syntax:
bsxfun(@times, myData, [5 10])
Più risposte (2)
Andrei Caragea
il 24 Nov 2011
Yes you can, with the eval function. Let me give you an example. Say you havein your workspace 3 variables: A, B, S, where A and B are doubles (matrices with numbers basically) and S is a cell like S={'A';'B'}. Then S(1)='A' and eval(S{1})=content of A (for example [1 2;3 4]). So now if f is your function, just do for i=1:2 f(eval(S{i})) end.
2 Commenti
Vedere anche
Categorie
Scopri di più su Whos in Help Center e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!