Why I see only the last value of my row vector in the workspace?

3 views (last 30 days)
I have the following row vectors in my program:
When I run my program, I see in the workspace only the last value of these row vectors as :
I don't know whether my program executes using only the last values of these row vectors or all. What modification my program needs so that I can see all these row vectors in my workspace instead of a singla value? My program is:
clear all; close all; clc;
cloud = 'Homo';
T_para = zeros(5, 17, 20);
T_per = zeros(5, 17, 20);
cth=[1010:10:1200]
h = [1000:1000:4000];
a = [0.01:0.01:0.05];
r = [4:1:20];
fov = [0.2 0.5 1 2 5 10]
snr=[30 40 50 65 75];
for h = 1000:1000:4000
for fov = [0.2 0.5 1 2, 5 10]
dir_arhf = ['Tabledata_', cloud, '\', num2str(h), 'm-', num2str(fov), 'mrad'];
mkdir(dir_arhf);
for a = 0.01:0.01:0.05
for r = 4:1:20
load (['MCdatabase_', cloud, '/', num2str(a), '-', num2str(r), 'um/', num2str(h), 'm-', num2str(fov), 'mrad/I0.mat']);
load (['MCdatabase_', cloud, '/', num2str(a), '-', num2str(r), 'um/', num2str(h), 'm-', num2str(fov), 'mrad/Q0.mat']);
I_para = 1/2 * (I0 + Q0);
I_per = 1/2 * (I0 - Q0);
hh = genHeight(h).^2;
beta_para = sum(I_para, 2) .* hh';
beta_per = sum(I_per, 2) .* hh';
T_para(a * 100, r-3, :) = beta_para';
T_per(a * 100, r-3, :) = beta_per';
Norm_para(a * 100, r-3, :)=(T_para(a * 100, r-3, :)./max(T_para(a * 100, r-3, :)));
Norm_per(a * 100, r-3, :)=(T_per(a * 100, r-3, :)./max(T_per(a * 100, r-3, :)));
for snr=[30, 40, 50, 65, 75]
snr_para(a * 100, r-3, :)=awgn(T_para(a * 100, r-3, :),snr);
snr_per(a * 100, r-3, :)=awgn(T_per(a * 100, r-3, :),snr);
costf=sqrt((snr_para(a * 100, r-3, :)-Norm_para(a * 100, r-3, :)).^2+(snr_per(a * 100, r-3, :)-Norm_per(a * 100, r-3, :)).^2);
save([dir_arhf, '\TABLE.mat'], 'T_per', 'T_para');
end
end
end
end
end
  1 Comment
Stephen23
Stephen23 on 19 Apr 2022
Look at your FOR loops:
h = [1000:1000:4000]; % this is totally unused
..
for h = 1000:1000:4000 % becaue you redefined h here
The same for all of those other variables.

Sign in to comment.

Accepted Answer

KSSV
KSSV on 19 Apr 2022
You are using the vector as the loop index so obviously you will find only the last value. You can check it your self.
for a = 0.01:0.01:0.05
a
end
a = 0.0100
a = 0.0200
a = 0.0300
a = 0.0400
a = 0.0500
fprintf('%f\n',a)
0.050000
You see, only the last value is printed, as it is the last index value. If you want it as a vector, you need to run like shown below.
a = 0.01:0.01:0.05;
for i = 1:length(a)
a(i)
end
ans = 0.0100
ans = 0.0200
ans = 0.0300
ans = 0.0400
ans = 0.0500
% after loop a
a
a = 1×5
0.0100 0.0200 0.0300 0.0400 0.0500

More Answers (0)

Categories

Find more on Parallel for-Loops (parfor) in Help Center and File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!