Rosa Gaghana
Rosa Gaghana

Reputation: 25

MATLAB - Make an array of quaternions data

I want to make an array with a set of quaternions data and i want to populate the array inside a loop. The problem is i can't put the quaternions data using a regular way to populate the array. How do i can make it right?

this is what i've tried

for ii=1:size(acc,1)
    %  quaternion data
    qahrs = ifilt(acc(ii,:), gyro(ii,:), mag(ii,:));
    %     supposed to be an array of quaternions
    orientation(ii) = qahrs;
end

Upvotes: 0

Views: 190

Answers (2)

Rosa Gaghana
Rosa Gaghana

Reputation: 25

I've solved it guys! Here's the solution

orientation = zeros('quaternion');
for ii=1:size(accCopy,1)
    qahrs = ifilt(accCopy(ii,:), gyro(ii,:), mag(ii,:));
    orientation(ii,1) = qahrs;
end

Upvotes: 0

lisonator
lisonator

Reputation: 128

It depends on dimensions of your quaternion data. If a single quaternion is (4x1) then:

orientation = zeros(4,n)
for ii=1:size(acc,1)
    %  quaternion data
    qahrs = ifilt(acc(ii,:), gyro(ii,:), mag(ii,:));
    %     supposed to be an array of quaternions
    orientation(:,ii) = qahrs;
end

and if it is (1x4)

orientation = zeros(n,4)
for ii=1:size(acc,1)
    %  quaternion data
    qahrs = ifilt(acc(ii,:), gyro(ii,:), mag(ii,:));
    %     supposed to be an array of quaternions
    orientation(ii,:) = qahrs;
end

I assumed that n is the number of quaternions.

Upvotes: 1

Related Questions