0
votes

I'm trying to display the current vector being used in my script.

I have a 'for loop' for an iteration and upon each change in the parameter

alpha = [0.5, 0.7, 0.85, 0.9, 0.95, 0.99];

I use

 disp(['alpha: ' num2str(alpha)])

and this outputs alpha: 0.5 etc for each one which is fine.

Now I'm also have another inner for loop changing the vector upon the iteration. The vectors are named

ri = [r1, r2, r3];

To which have already been defined. Now as above with disp... alpha. I wish to display which current vector is being used. The same method of num2str doesn't work. Probably as it is a vector. I just want the value r1, etc to be displayed.

alph = [0.5, 0.7, 0.85, 0.9, 0.95, 0.99];

ri = [r1, r2, r3];

for alpha = alph,
    disp(['alpha: ' num2str(alpha)])
    for r = ri,  %
          for k = 1:200,
          (code takes up too much room, just an iteration)
          end
          disp(['number of iterations: ' num2str(k)])
         ******
     end
end

I also want to include at ***** display vector r1 or r2 or r3
1
Please show your code and/or make the question clearer - Luis Mendo
Do you mean that r1, r2 etc are column vectors? - Luis Mendo
yes they are. but I don't wish to display the actual vector just which vector has been used. if that make sense? - user3288167
Just an index for the vector (1, 2, 3,... )? - Luis Mendo
Here. This might make more sense dropbox.com/s/0r66wb40rl6lo94/… As it says alpha= blah I also want it to say r1 or r2 whichever its meant to be - user3288167

1 Answers

0
votes

To display the value of the vector, you can use num2str, but you need to transpose so that num2str gives a row to be contatenated with the rest of the string:

for r = ri
    disp(['r: ' num2str(r.')])
end

Alternatively, use mat2str:

for r = ri    
    disp(['r: ' mat2str(r)])
end

To display an index of the used vector: define your for loop directly with an index:

for index = 1:size(ri,2)
    r = ri(:,index);
    disp(['Column used: ' num2str(index)])
end