www.gusucode.com > 汽车转动仿真源码程序 > 汽车转动仿真源码程序/汽车转动仿真1/Adams_Car_Data_Processing/Processor.m
%% User Setting... clear;clc;close all; % Step 1 % Setting Full Vehicle Simulation or Suspension Simulation % Note: % ----- '<Step type="quasiStatic">' is for Suspension Simulation % ----- '<Step type="initialConditions">' is for Full Vehicle Simulation Simulation_Type='<Step type="initialConditions">'; % Step 2 % Input the RES file name % For example, a file named 'full_vehicle_step.res' fname = 'full_vehicle_step'; % Step 3 % Setting the output variables: % Note: % ------ Make sure to add a blank space at the end of each variable name. % ------ All the variable names must be the same with those in % Adams/PostProcessor % for example, you want to output 6 variables output_var=[ 'time_TIME ' ... %time 'cm_velocity_longitudinal ' ... %vx 'cm_acceleration_lateral ' ... %ay 'cm_displacement_roll ' ... %roll angle 'condition_sensors_yaw_rate '... %yaw rate 'condition_sensors_side_slip_angle ']; %side slip %% Processing... res='res';txt='txt';string='_string';number='_number';all='all'; % Firstly, save all the data to a *.txt file f0=strcat(fname,'.',res); f1=strcat(fname,string,'.',txt); f2=strcat(fname,number,'.',txt); fin=fopen(f0); fidout=fopen(f1,'w'); find_string(fin,fidout); fidin=fopen(f0); fidout=fopen(f2,'w'); find_numbers(fidin,fidout,Simulation_Type); % Secondly, loading the data from *.txt file to workspace Name = importdata(f1); Name = Name{1}; Name = textscan(Name, '%s'); Name = Name{1}; fin2=fopen(f2); data = textscan(fin2, '%f'); data = cell2mat(data); % Thirdly, reshaping the data to a matrix L = length(Name); K = length(data)/L; data = reshape(data,L,K); data =data'; %% Data Outputing D=textscan(output_var,'%s '); D=D{1}; N=length(D); OUTPUT=zeros(K,N); for k=1:N s=strcmp(D{k},Name); if sum(s)~=1 disp('Error with certain variable name:') disp(strcat('Cannot find the ',num2str(k),'variable:',D{k})) break; end [a,b]=sort(s); M=b(end); OUTPUT(:,k)=data(:,M); end %% Plotting... time=OUTPUT(:,1); vx =OUTPUT(:,2); ay =-OUTPUT(:,3); roll =OUTPUT(:,4); yawrate =OUTPUT(:,5); slip =OUTPUT(:,6); figure; plot(time,yawrate,'linewidth',2) grid on; set(gcf,'color','w') xlabel('Time/s') ylabel('Yawrate/rad/s') title('Full vehicle simulation yawrate')