for r = r(:,1)
This redefines the variable r. Before the loop executes, r is a 3-by-7 matrix. After the loop, r will be a 3-by-1 column vector and you won't be able to get any of the remaining columns that used to be in r, because r has been redefined to include only its first column.
Recall that a for loop iterates over the columns of what you give it, so if you say, "for index = valArray", then (from the documentation):
- valArray — Create a column vector, index, from subsequent columns of array valArray on each iteration. For example, on the first iteration, index = valArray(:,1). The loop executes a maximum of n times, where n is the number of columns of valArray, given by numel(valArray(1,:)). The input valArray can be of any MATLAB® data type, including a character vector, cell array, or struct.
Therefore, giving a for loop a column vector causes it to iterate only once, so the for loop is not even necessary. It's the same as saying r = r(:,1) and then executing the code inside the loop once. Looked at this way, of course you only get results corresponding to the first column of r.
The same problem applies to the other loop, which uses "for i = i(:,1)".
What you can do is get rid of those for statements and put the code inside those loops directly inside the outer loop over col, and that becomes the only loop you'll have. Something like this (I'm also renaming the variables r and i because for one thing it's not advisable to use i since it can be confused with the imaginary unit 1i):
R_real = real(R)
R_imag = imag(R)
[numRows, numCols] = size(R)
for col = 1:numCols %for each column of R
% create a new figure
h = figure;
% calculate delta_w_r and omegar for this column of R_real, i.e., R_real(:,col)
delta_w_r = (R_real(:,col) * (n_bn_0)^(1/3)) .* (k .* V_s)./((1 + (klambda_D).^2).^(1/2));
omegar = ((k .* V_s)./((1 + (klambda_D).^2).^(1/2)) + delta_w_r)/w_pe;
% plot
q = plot(omegar, klambda_D, '-');
ylim([-0.1 0.1]);
hold on
grid on
% calculate delta_w_i and omegai for this column of R_imag, i.e., R_imag(:,col)
delta_w_i = (R_imag(:,col) * (n_bn_0)^(1/3)) .* (k .* V_s)./((1 + (klambda_D).^2).^(1/2));
omegai = ((k .* V_s)./((1 + (klambda_D).^2).^(1/2)) + delta_w_i)/w_pe;
% plot
b = plot(omegai, klambda_D, '--');
% create a legend
lgd = legend('Location', 'northwest');
lgd.FontSize = 14;
lgd.Title.String = 'Disp relations';
% set axes labels
xlabel('k * \lambda_D')
ylabel(' omega \omega')
% save the figure
saveas(h,sprintf('omega3%d.png',col));
end
(Note that I also moved where you create the figures because it didn't make any sense to me how you had it:)
% create a new figure
h = figure;
% modify some axes properties
xlabel('k * \lambda_D')
ylabel(' omega \omega')
hold on
% save the figure (but nothing has been plotted in this figure?!)
saveas(h,sprintf('omega3%d.png',col));
