![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/894145/image.png)
How can I write a loop that will normalise each column of data to zero?
1 次查看(过去 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.
0 个评论
采纳的回答
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 ?
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/894145/image.png)
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 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Whos 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!