- 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 views (last 30 days)
Show older comments
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 Comments
Answers (1)
Yash
on 29 Aug 2023
Edited: Yash
on 29 Aug 2023
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 Comments
See Also
Categories
Find more on Annotations 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!