Question: I need help with the following MATLAB code. I want to pull out 8 matrices from the nested for loop. I want four matrices for
I need help with the following MATLAB code. I want to pull out matrices from the nested for loop. I want four matrices for each noise level for guassian and possion distribution defined to a variable. How do I do that?
Number of unit vectors
n ;
Define noise levels in degrees
noiselevelsdeg ; arcseconds and degrees
Define a random rotation matrix Direction Cosine Matrix
R orthrandn; x orthogonal matrix
Generate random unit vectors in the body frame
unitvectorsbody randn n;
unitvectorsbody unitvectorsbody vecnormunitvectorsbody;
Define noise distributions Gaussian and Poisson
for noisetype Gaussian "Poisson"
dispNoise Type: charnoisetype;
for i :lengthnoiselevelsdeg
noiselevel noiselevelsdegi;
Convert noise level to radians
noiselevelrad degradnoiselevel;
dispNoise Level: numstrnoiselevel degrees';
Initialize arrays to hold noisy vectors
noisyvectorsbody zeros n;
noisyvectorsinertial zeros n;
for j :n
Apply noise to the unit vectors
if noisetype "Gaussian"
noise noiselevelrad randn; Gaussian noise
else
noise noiselevelrad poissrnd; Poisson noise
end
Perturb the unit vector's direction
perturbedvector unitvectorsbody: j noise;
perturbedvector perturbedvector normperturbedvector; Renormalize
Store noisy vector in body frame
noisyvectorsbody: j perturbedvector;
Transform to inertial frame using rotation matrix
noisyvectorsinertial: j R perturbedvector;
end
Display the noisy vectors in the inertial frame for this noise level
dispNoisy Vectors in Inertial Frame:;
dispnoisyvectorsinertial;
end
end
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
