- After determining the side of the sensor using the strcmp condition, you can create a logical index to select the appropriate side of the V sensor data.
- Use the logical index to plot only the selected side of the V sensor data.
How to plot a specific variable if condition is met
2 次查看(过去 30 天)
显示 更早的评论
Hi,
I have code that is comparing two sensors (Ms and V). V measures both left and right, however Ms measures only the side that it is placed on. I would like to only plot the correct side of V so that it corresponds to Ms, instead of plotting both left and right of V.
I have previously read in whether the file I am workign with is the left or the right side, in order to use cross correlation to time synchronise the different sensor files, please see below.
if strcmp(sensorside{1,1},cellstr('left'))
disp('left!');
[r,lags] = xcorr(angles{1,i}.LKneeAngles(:,1),MS_knee_angle2,numrows_Vic(i)); %tried alignsignals instead of xcorr
elseif strcmp(sensorside{1,1},cellstr('right'))
disp('right!');
[r,lags] = xcorr(angles{1,i}.RKneeAngles(:,1),MS_knee_angle2,numrows_Vic(i));
else
error('Help!');
end
How would I go about plotting only the left or only the right side for the V sensor depending on what side the sensor is placed? I am not sure how to do the if loop for a figure.
%% Time synch plot for MS and Vicon _changed 19/08/2022
figure
plot(time', sync(i).V_LK);
hold on
plot(time',sync(i).V_RK);
hold on
plot(time',sync(i).MS_K);
title('Time synchronised plots comparing MS to Vicon for activity',activity);
legend('Vicon left knee', 'Vicon right knee','MotionSense');
Thank you so much for any advice
0 个评论
回答(1 个)
Yash
2023-8-29
编辑:Yash
2023-8-29
Hi Alexandra,
To plot only the correct side of the V sensor that corresponds to the side of the Ms sensor, you can modify your code as follows:
Here's an example of how you can modify your code:
if strcmp(sensorside{1, 1}, 'left')
v_sensor_side = sync(i).V_LK; % Select the left side of V sensor data
elseif strcmp(sensorside{1, 1}, 'right')
v_sensor_side = sync(i).V_RK; % Select the right side of V sensor data
While plotting, plot v_sensor_side only.
% Plot the selected side of the V sensor data
figure
plot(time, v_sensor_side);
hold on
plot(time, sync(i).MS_K);
In the modified code, we create a variable v_sensor_side and assign the appropriate side of the V sensor data based on the side of the Ms sensor. Then, we plot the selected side of the V sensor data along with the Ms sensor data.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Annotations 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!