How can I write a loop that will normalise each column of data to zero?

3 次查看(过去 30 天)
Hi everyone,
I have a data set where I am trying to normalise each column of data to start at 0 degrees, and be in a positive direction (angular data). As the data flips when it reaches 180 degrees, I also need to account for this, so each column should move from approximately 0-90 degrees. The data also needs to be interpolated and transposed for further analysis.
I am currently stuck trying to write a loop to normalise each data column to start at 0 degrees. This is what I have tried so far:
head_rot=readmatrix('Head_Rotation_Data');
sho_rot=readmatrix('Shoulder_Rotation_Data');
head_rot_unwrap=unwrap(head_rot*pi/180)*180/pi;
sho_rot_unwrap=unwrap(sho_rot*pi/180)*180/pi;
for normalise_loop=1:size(head_rot_unwrap,1) %do separately for each time series (i.e. each participant or each trial)
hr_norm(:,normalise_loop)= (head_rot_unwrap(:,normalise_loop) - head_rot_unwrap(1,normalise_loop));
sr_norm(:,normalise_loop)= (sho_rot_unwrap(:,normalise_loop) - sho_rot_unwrap(1,normalise_loop));
end
head_rot_interp=inpaint_nans(hr_norm);
sho_rot_interp=inpaint_nans(sr_norm);
head_rot_transpose=transpose(head_rot_interp);
sho_rot_transpose=transpose(sho_rot_interp);
It is coming up with the error message:
Error using size
Not enough input arguments.
Error in normalise_to_baseline90 (line 8)
hr_norm(:,size)= 0-(head_rot_unwrap(:,size) - head_rot_unwrap(1,size));
I would appreciate any input as to what is going wrong/some suggestions on how I can change and improve this! I still get a bit stuck writing loops, so any hints and tips you've got would also be great if you have any. I've included the sample dataset but you probably don't need to look at is specifically.

采纳的回答

Mathieu NOE
Mathieu NOE 2022-2-14
hello
IMHO there was only this bug
then you can see we can plot the data (unwrapped) without any issue
for normalise_loop=1:size(head_rot_unwrap,1)
must be
for normalise_loop=1:size(head_rot_unwrap,2)
now what do we do next? the data do not have same length for each measurement , so I suspect you would like to extraoplate , or we cut the longest ones to be of same length as the shortest one ?
full code
clc
clearvars
head_rot=readmatrix('Head_Rotation_Data');
sho_rot=readmatrix('Shoulder_Rotation_Data');
head_rot_unwrap=unwrap(head_rot*pi/180)*180/pi;
sho_rot_unwrap=unwrap(sho_rot*pi/180)*180/pi;
for normalise_loop=1:size(head_rot_unwrap,2) %do separately for each time series (i.e. each participant or each trial)
hr_norm(:,normalise_loop)= (head_rot_unwrap(:,normalise_loop) - head_rot_unwrap(1,normalise_loop));
sr_norm(:,normalise_loop)= (sho_rot_unwrap(:,normalise_loop) - sho_rot_unwrap(1,normalise_loop));
end
figure(1),
subplot(211),plot(hr_norm)
title('Head Rotation Data');
subplot(212),plot(sr_norm)
title('Shoulder Rotation Data');
  3 个评论
pkll201
pkll201 2022-2-14
You're amazing, thank you so much for your help, and your advice regarding the rest of the code! The reason I need it to be transposed is for further analysis that needs to be done :)

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Surface and Mesh Plots 的更多信息

产品


版本

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by