MATLAB: How to add 2 specific channels out of 6 channels of data from a text file on the Y-Axis

chart;multiple yaxisplotplottingsubplottext file

Hello, I am new to Matlab so please have patients. I have a m-file (created by others) as shown below. It calls a text file with 6 channels of data.
What I would like to do is create a new m-file (save-as) and plot for example the "Actuator_Extend_Pressure" as it currently is but add a second yaxis label from the "Analog1" channel which is: Ao1 = Motor Velocity Command (3000[RPM]/10[V]). The new/added y-axis would be in RPM and on the right side of the graph. So I would have a y-axis on the left in PSI and a y-axis on the right in RPM. I would do this for one or more files as needed and keep the others the same as they currently are.
Thank you for your help.
Current m-file:
function [Filtered_Data] = EHA_Filter( filename, Fs, Coef)
%EHA_Filter Summary of this function goes here
% Detailed explanation goes here
%-----------------Import .txt data-------------------

%----------------------------------------------------





Y = importdata(filename, '\t',7);
Y = Y.data;
Y = Y.';
Filtered_Data = Y;
L = length(Y(1,:));
T = (1/Fs);
t = T*linspace(0,L-1,L);
%----------------------------------------------------
%-----------------Import .txt data-------------------
%-----------------------FIR--------------------------

%----------------------------------------------------
Analog1 = filter(Coef(1:3),Coef(4:6),Y(1,:));
Analog2 = filter(Coef(1:3),Coef(4:6),Y(2,:));
Pump_Extend_Pressure = filter(Coef(1:3),Coef(4:6),Y(3,:));
Pump_Retract_Pressure = filter(Coef(1:3),Coef(4:6),Y(4,:));
Actuator_Extend_Pressure = filter(Coef(1:3),Coef(4:6),Y(5,:));
Actuator_Retract_Pressure = filter(Coef(1:3),Coef(4:6),Y(6,:));
%----------------------------------------------------
%-----------------------FIR--------------------------
%-----------------------Plot-------------------------

%----------------------------------------------------
trd_scale = 3000/100e-3; %3000[PSI]/100[mV]
figure
subplot(2,3,1), plot(t,Y(1,:),'b')
hold on
subplot(2,3,1), plot(t,Analog1,'r')
title('Analog Input 1')
xlabel('Time [s]')
ylabel('Voltage [V]')
subplot(2,3,2), plot(t,Y(2,:),'b')
hold on
subplot(2,3,2), plot(t,Analog2,'r')
title('Analog Input 2')
xlabel('Time [s]')
ylabel('Voltage [V]')
subplot(2,3,3), plot(t,Y(3,:)*trd_scale,'b')
hold on
subplot(2,3,3), plot(t,Pump_Extend_Pressure*trd_scale,'r')
title('Pump Extend Pressure')
xlabel('Time [s]')
ylabel('Pressure [PSI]')
subplot(2,3,4), plot(t,Y(4,:)*trd_scale,'b')
hold on
subplot(2,3,4), plot(t,Pump_Retract_Pressure*trd_scale,'r')
title('Pump Retract Pressure')
xlabel('Time [s]')
ylabel('Pressure [PSI]')
subplot(2,3,5), plot(t,Y(5,:)*trd_scale,'b')
hold on
subplot(2,3,5), plot(t,Actuator_Extend_Pressure*trd_scale,'r')
title('Actuator Extend Pressure')
xlabel('Time [s]')
ylabel('Pressure [PSI]')
subplot(2,3,6), plot(t,Y(6,:)*trd_scale,'b')
hold on
subplot(2,3,6), plot(t,Actuator_Retract_Pressure*trd_scale,'r')
title('Actuator Retract Pressure')
xlabel('Time [s]')
ylabel('Pressure [PSI]')
%----------------------------------------------------
%-----------------------Plot-------------------------
end

Best Answer

  • Use the plotyy command. That's exactly what you are looking for.