Separating a 3 variable dataset with repeating values into a multivariable dataset quickly.

1 view (last 30 days)
I have a 3 variable data set from an experiment. A sensor took magnetic intensity readings around 360 degrees of rotation at 0.1mm radial increments. The data logger gave me these variables.
An angular variable that repeats from 0 to 360 (yes I am aware of the duplication of 0 and 360. Its actually important) for each of the increments.
A radial variable that goes from 0 to 23.3 in 0.1 increments (so there are 361 values of 0, then 361 values of 0.1, then 361 values of 0.2 etc).
The intensity reading at each angle and displacement.
I want to separate the variables so that the angle variable goes from 0 to 360 JUST ONCE, 0 to 23.3 becomes an array of variable headers and the intensities then fill those variables.
So I am asking is there a way to sort a 3 variable problem into a 234 variable problem where the 3 variable problem has a variable that repeats 233 times and a variable that will make up the headers of the new 233 variables (the contents of which is comprised of the contents of the 3rd original variable).
Just incase my rambling cant be understood, here is a sample of one of the data sets.
I am working in Octave but have Matlab at home if it can only be done in one of them.

Answers (1)

Namita Vishnubhotla
Namita Vishnubhotla on 22 Jul 2014
The following script should help you with your data if you have it in 3 columns like in your sample data set.
I believe the variable names are self-explanatory.
Code:
rows = unique(originalData(:,1));
cols = unique(originalData(:,2));
j = 1;
k = 1;
values = zeros(size(rows,1),length(cols));
while(j <= size(values,2))
values(:,j) = originalData(k:k+size(new,1)-1,3);
j = j + 1;
k = k + size(new,1);
end
requiredData = [cols';values];
rows = [nan;rows];
finalData = [rows requiredData];
  1 Comment
Namita Vishnubhotla
Namita Vishnubhotla on 22 Jul 2014
Note that this will work only if column 1 and column 2 of the original data are already sorted, as the "unique" command returns values in sorted order.

Sign in to comment.

Categories

Find more on Data Import and Analysis in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!