Borrar filtros
Borrar filtros

How to plot a specific variable if condition is met

2 visualizaciones (últimos 30 días)
alexandra ligeti
alexandra ligeti el 14 de Sept. de 2022
Editada: Yash el 29 de Ag. de 2023
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'))
[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'))
[r,lags] = xcorr(angles{1,i}.RKneeAngles(:,1),MS_knee_angle2,numrows_Vic(i));
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
plot(time', sync(i).V_LK);
hold on
hold on
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

Respuestas (1)

Yash el 29 de Ag. de 2023
Editada: Yash el 29 de Ag. de 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:
  1. 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.
  2. Use the logical index to plot only the selected side of the V sensor data.
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
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.


Más información sobre Bar Plots en Help Center y File Exchange.


Community Treasure Hunt

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

Start Hunting!

Translated by