Working with different variables in Cycle
2 views (last 30 days)
Show older comments
Hi i have question.
Basically i have a for cycle and in every iteration I would like to use different Variable.
I have for example Variable C which is matrix and I want to use first column and all rows so C(:,1). I have several variables with different names like D1, D2, T1, T2 and so on.
So in the first iteration i=1 I want to use variable C and in i=2 variable D2 and so on.
Now I looking for a way how to manage it. I tried some cell2mat but it didn't work.
Part of the code I have:
Par = cell2mat(Param(i)) % In Param cell i have stored names of variables where Param(1)=C and Param(2)=D1 for example
ind = find(P_VB(1,1)==Par(:,1)); %Now i would like from matlab to substitute Par with C is it would be ...C(:,1);
Hope it makes sense what i want to achieve.
Thanks a lot.
0 Comments
Accepted Answer
Jan
on 26 Apr 2012
Using D1, D2, ... als variables must lead to such problems, see: FAQ: Create A1, A2, ... in a loop. And if you have loaded the FAQ already, take the time to read the other topic also.
Better use the cell array D{1}, D{2}, ... Then the variables are easy to access inside a loop.
0 Comments
More Answers (1)
See Also
Categories
Find more on Data Type Conversion 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!