Reputation: 1131
How to evaluate a string which could be changed dynamically in code? for example:
A=rand(60, 60);
RangeC='10:end,:';
B=A(RangeC);
I know this is quite easy for others, but I have struggled for hours! Thanks in advance!
Upvotes: 0
Views: 20
Reputation: 1110
You can use the eval
function but I would suggest to seperate RangeC in two variables like the example below. Also end
won't be able to be evaluated so you can use size
instead.
A=rand(60, 60);
RangeC1='10:size(A,1)';
RangeC2='1:size(A,2)';
B=A(eval(RangeC1), eval(RangeC2));
Upvotes: 1