Question: I need help with my code in MATLAB. I am trying to pull out each of the 8 matrices I created in the loop as

I need help with my code in MATLAB. I am trying to pull out each of the 8 matrices I created in the loop as shown in the code in the end. It is giving me an error or just says 1\times 1 cell array {3\times 10 double}. Can you help me pull each matrix out?
clc; clear all;
% Number of unit vectors
n =10;
% Define noise levels in degrees
noise_levels_deg =[1/3600,10/3600,1,5];
% Define a random rotation matrix (Direction Cosine Matrix)
R = orth(randn(3));
% Generate 10 random unit vectors in the body frame
unit_vectors_body = randn(3, n);
unit_vectors_body = unit_vectors_body ./ vecnorm(unit_vectors_body);
% Pre-allocate matrices to store the noisy vectors for Gaussian and Poisson noise
noisy_vectors_body_gaussian = cell(1, length(noise_levels_deg));
noisy_vectors_inertial_gaussian = cell(1, length(noise_levels_deg));
noisy_vectors_body_poisson = cell(1, length(noise_levels_deg));
noisy_vectors_inertial_poisson = cell(1, length(noise_levels_deg));
% Define noise distributions
noise_types =["Gaussian", "Poisson"];
% Loop through noise types (Gaussian and Poisson)
for noise_type = noise_types
disp(['Noise Type: ', char(noise_type)]);
% Loop through noise levels
for i =1:length(noise_levels_deg)
noise_level = noise_levels_deg(i);
% Convert noise level to radians
noise_level_rad = deg2rad(noise_level);
disp(['Noise Level: ', num2str(noise_level),' degrees']);
% Initialize arrays to hold noisy vectors
noisy_vectors_body = zeros(3, n);
noisy_vectors_inertial = zeros(3, n);
% Loop through unit vectors
for j =1:n
% Apply noise to the unit vectors
if noise_type == "Gaussian"
noise = noise_level_rad * randn(3,1); % Gaussian noise
else
noise = noise_level_rad * poissrnd(1,3,1); % Poisson noise
end
% Perturb the unit vector's direction
perturbed_vector = unit_vectors_body(:, j)+ noise;
perturbed_vector = perturbed_vector / norm(perturbed_vector); % Renormalize
% Store noisy vector in body frame
noisy_vectors_body(:, j)= perturbed_vector;
% Transform to inertial frame using rotation matrix
noisy_vectors_inertial(:, j)= R * perturbed_vector;
end
% Store the noisy vectors for each noise level and distribution
if noise_type == "Gaussian"
noisy_vectors_body_gaussian{i}= noisy_vectors_body;
noisy_vectors_inertial_gaussian{i}= noisy_vectors_inertial;
else
noisy_vectors_body_poisson{i}= noisy_vectors_body;
noisy_vectors_inertial_poisson{i}= noisy_vectors_inertial;
end
% Display the noisy vectors in the inertial frame for this noise level
% disp('Noisy Vectors in Inertial Frame:');
% disp(noisy_vectors_inertial);
end
end
a = noisy_vectors_inertial_guassian(1)
b = noisy_vectors_inertial_guassian(2)
c = noisy_vectors_inertial_guassian(3)
d = noisy_vectors_inertial_guassian(4)
e = noisy_vectors_inertial_poisson(1)
f = noisy_vectors_inertial_poisson(2)
g = noisy_vectors_inertial_poisson(3)
h = noisy_vectors_inertial_poisson(4)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!