How can I add uncertainty to a data matrix?

I obtained a signal data by running a simulation with input parameters. Some of these inputs are h,a,r,fov as shown in the following program. The output signals are beta_para and beta_per. The output signals are highly influenced by these four input parameters. What I want now is to add uncertainty to the inputs like fov±0.005 and obtained the signals with the input error. One way to do this is to repeat the simulation and input the parameters with uncertainties and obtained the output signals with error, however the process is very lengthy because my data is too big. I had come to know that we can deal it using repmat function in matlab as well without repeating the simulation. I don't know how can I use the repmat function to add uncertainties of the input parameters h,a,r,and fov to the signals beta_para and beta_per. Please if anybody can help me in this regard. My program is::
clear all,clc,close all
cloud = 'Homo';
T_para = zeros(5, 17, 20);
T_per = zeros(5, 17, 20);
h = 1000:1000:4000;
a = 0.01:0.01:0.05;
r = 4:1:20;
fov = [0.2, 0.5, 1, 2, 5, 10];
for i=1:length(h)
for j=1:length(fov)
dir_arhf = ['Tabledata_', cloud, '\', num2str(h(i)), 'm-', num2str(fov(j)), 'mrad'];
mkdir(dir_arhf);
for k=1:length(a)
for m=1:length(r)
load (['MCdatabase_', cloud, '/', num2str(a(k)), '-', num2str(r(m)), 'um/', num2str(h(i)), 'm-', num2str(fov(j)), 'mrad/I0.mat']);
load (['MCdatabase_', cloud, '/', num2str(a(k)), '-', num2str(r(m)), 'um/', num2str(h(i)), 'm-', num2str(fov(j)), 'mrad/Q0.mat']);
I_para = 1/2 * (I0 + Q0);
I_per = 1/2 * (I0 - Q0);
hh = genHeight(h(i)).^2;
beta_para = sum(I_para, 2) .* hh';
beta_per = sum(I_per, 2) .* hh';
T_para(a(k) * 100, r(m)-3, :) =beta_para';
T_per(a(k) * 100, r(m)-3, :) =beta_per';
save([dir_arhf, '\TABLE.mat'], 'T_per', 'T_para');
end
end
end
end

 Accepted Answer

The repmat funciton is likely not needed. Just do something like this:
h = h + randn(size(h));
and so for the rest.
See the randn documentation for details.
.

12 Comments

The function works. But actually the values of these inputs are also assigned to the title of the data in the address. Using randn changes the values of these inputs and then the program is unable to locate and load the data. It shows the following error:
I used it as:
clear,clc,close all
cloud = 'Homo';
T_para = zeros(5, 17, 20);
T_per = zeros(5, 17, 20);
h = 1000:1000:4000;
h=h+randn(size(h))
a = 0.01:0.01:0.05;
a=a+randn(size(a));
r = 4:1:20;
r=r+rand(size(r))
fov = [0.2, 0.5, 1, 2, 5, 10];
fov=fov+randn(size(fov))
for i=1:length(h)
for j=1:length(fov)
dir_arhf = ['Tabledata_', cloud, '\', num2str(h(i)), 'm-', num2str(fov(j)), 'mrad'];
mkdir(dir_arhf);
for k=1:length(a)
for m=1:length(r)
load (['MCdatabase_', cloud, '/', num2str(a(k)), '-', num2str(r(m)), 'um/', num2str(h(i)), 'm-', num2str(fov(j)), 'mrad/I0.mat']);
load (['MCdatabase_', cloud, '/', num2str(a(k)), '-', num2str(r(m)), 'um/', num2str(h(i)), 'm-', num2str(fov(j)), 'mrad/Q0.mat']);
I_para = 1/2 * (I0 + Q0);
I_per = 1/2 * (I0 - Q0);
hh = genHeight(h(i)).^2;
beta_para = sum(I_para, 2) .* hh';
beta_per = sum(I_per, 2) .* hh';
T_para(a(k) * 100, r(m)-3, :) =beta_para';
T_per(a(k) * 100, r(m)-3, :) =beta_per';
save([dir_arhf, '\TABLE.mat'], 'T_per', 'T_para');
end
end
end
end
Add the randn calls somewhere before you use the parameters. It does not have to be where I put them, since that was simply an illustration.
Could you please be more specific that where I need to put? As I tried every position but faced error everytime.
I do not see where ‘fov’ is used except in the load calls.
For the others, something like this will add randomness without altering the initial vectors —
hh = genHeight(h(i)+randn).^2;
beta_para = sum(I_para, 2) .* hh';
beta_per = sum(I_per, 2) .* hh';
Then remove the previous randomisations (before the loop), since they cause problems.
The others are used as part of the subscripts, so randomising those using randn will cause those to fail. Using randi instead will keep them as integers, however if the objective is to select random values in the matrices, there are better ways to do it. One option for that would be randi, another would be randperm.
Otherwise, I am not certain what you want to randomise.
.
Thank you for your elaboration. Actually fov is used as the input parameter to obtain the output data ( beta_para and beta_per) from the simulation. We mentioned the fov in the load call to collect the data for each value of fov using for loop. Now I want to add uncertainty to the input fov like fov±0.005 and to get the output data with uncertainty. It can be done by repeating the simulation to input the fov with uncertainty. However I want the bypass way using matlab to get the output data if the uncertainty is involved in the fov like fov±0.005. Is there any other way to do this?
The only instances I see the parameters being used is in the specification of dir_arhf directory and file name elements, and as matrix indices. Those have strict requirements, and may not tolerate anything except integers.
What exactly does the simulation do?
What are the arguments to it?
Where is it referenced in the code?
Thank you so much.
As always, my pleasure!
I will continue to help if I have some information on how you are doing the simulation so that I can randomise the parameters correctly. As I interpret your code, the parameters are being used in paths, file names, and matrix subscripts, so they need to be kept as values that will work in those instances. I doubt that I have access to the cloud files, so I cannot run the code to check it and test it with any changes I introduce.
That's a great favour of you. Its my pleasure to share my cloud files with you so that you can make correction where needed but actually the size of the data files exceeds the limit of the attachment and I'm unable to do so. Else, I don't know any other ways to share you.
Not sharing the files is not a problem. My objective is to help randomise the initial values of the parameters for the simulation. That is not obvious because I have no idea what the simulation is or does, or how it is called.
I got it. Thank you
As always, my pleasure!

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!