there is b1, b2, b3 variables but i just want to call them by using i indicator in matlab

You can use the eval function in MATLAB to evaluate the value of a variable whose name is stored as a string. Here is an example:

main.m
b1 = 10;
b2 = 20;
b3 = 30;

for i = 1:3
    var_name = sprintf('b%d', i);
    value = eval(var_name);
    fprintf('%s = %d\n', var_name, value);
end
149 chars
10 lines

This code will loop over i values of 1, 2, and 3, and construct the variable names b1, b2, and b3 using sprintf. It will then evaluate the value of the variable with that name using eval, and print out the results using fprintf.

related categories

gistlibby LogSnag