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 matrices I created in the loop as shown in the code in the end. It is giving me an error or just says times cell array times double Can you help me pull each matrix out?
clc; clear all;
Number of unit vectors
n ;
Define noise levels in degrees
noiselevelsdeg ;
Define a random rotation matrix Direction Cosine Matrix
R orthrandn;
Generate random unit vectors in the body frame
unitvectorsbody randn n;
unitvectorsbody unitvectorsbody vecnormunitvectorsbody;
Preallocate matrices to store the noisy vectors for Gaussian and Poisson noise
noisyvectorsbodygaussian cell lengthnoiselevelsdeg;
noisyvectorsinertialgaussian cell lengthnoiselevelsdeg;
noisyvectorsbodypoisson cell lengthnoiselevelsdeg;
noisyvectorsinertialpoisson cell lengthnoiselevelsdeg;
Define noise distributions
noisetypes Gaussian "Poisson";
Loop through noise types Gaussian and Poisson
for noisetype noisetypes
dispNoise Type: charnoisetype;
Loop through noise levels
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;
Loop through unit vectors
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
Store the noisy vectors for each noise level and distribution
if noisetype "Gaussian"
noisyvectorsbodygaussiani noisyvectorsbody;
noisyvectorsinertialgaussiani noisyvectorsinertial;
else
noisyvectorsbodypoissoni noisyvectorsbody;
noisyvectorsinertialpoissoni noisyvectorsinertial;
end
Display the noisy vectors in the inertial frame for this noise level
dispNoisy Vectors in Inertial Frame:;
dispnoisyvectorsinertial;
end
end
a noisyvectorsinertialguassian
b noisyvectorsinertialguassian
c noisyvectorsinertialguassian
d noisyvectorsinertialguassian
e noisyvectorsinertialpoisson
f noisyvectorsinertialpoisson
g noisyvectorsinertialpoisson
h noisyvectorsinertialpoisson
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
