我该如何改进此代码以将振荡信号从csv导入到matlab中

问题描述:

我创建的这个Matlab函数基本上需要一个由tektronix振荡器生成的csv文件并绘制两个通道的信号。但是,创建的每个测试和csv文件都有不同数量的点(对于这种情况,其格式为9999,意思是[B16:B10014]),而excell中的工作表的名称不同(tek0001ALL)。我是新来的matlab,这可能不是最好的代码效率的方式来做到这一点,所以我想知道是否可以有一个更简单的方法有一个通用的代码,可以绘制任何生成的csv,可以检测到最后一个单元格填充那些柱子和单元的数量,所以它也可以是点数,因为有时它需要进行大量的测试。我该如何改进此代码以将振荡信号从csv导入到matlab中

function [ Vs1, Vs2, t ] = scope![enter image description here][1](filename) 

% Read the Y axis data of the scope data in volts CH1 
Vs1 = xlsread(filename, 'tek0001ALL', 'B16:B10014'); 
% Read the Y axis data of the scope data in volts CH2 
Vs2 = xlsread(filename, 'tek0001ALL', 'C16:C10014'); 
% Read the sample interval from the scope data in seconds 
sample_interval = xlsread(filename, 'tek0001ALL', 'B7'); 
% Create time axis 
t = 0:sample_interval:(9999*sample_interval)-sample_interval; 

%Plot waveform 
figure 
subplot(2,1,1); 
plot(t,Vs1); 
title('Sensor Input Measurements for 100pc Discharge '); 
xlabel('Time[s]'); 
ylabel('Voltage[V]'); 
grid on; 
grid minor; 

subplot(2,1,2); 
plot(t,Vs2); 
title('Sensor Output Measurements for 100pc Discharge'); 
xlabel('Time[s]'); 
ylabel('Voltage[V]'); 
grid on; 
grid minor; 

end 

CSV文件格式的例子如下:

Model,DPO3034 
Firmware Version,1.08 

Point Format,Y, 
Horizontal Units,S, 
Horizontal Scale,8e-07, 
Sample Interval,8e-10, 
Record Length,10000, 
Gating,0.0% to 99.9900%,0.0% to 99.9900% 
Probe Attenuation,1,1 
Vertical Units,V,V 
Vertical Offset,0,0 
Vertical Scale,0.05,0.001 
Label,, 
TIME,CH1,CH2 
-1.4664e-06,-0.003,-0.00036 
-1.4656e-06,-0.003,-0.00036 
-1.4648e-06,-0.003,-0.00036 
-1.4640e-06,-0.001,-0.00032 
-1.4632e-06,-0.003,-0.00036 
-1.4624e-06,-0.001,-0.00036 
-1.4616e-06,-0.001,-0.0004 
-1.4608e-06,-0.003,-0.00036 

如果您在CSV文件离开的数据,你可以使用csvread这让一切变得简单。

function [ Vs1, Vs2, t ] = scope(filename) 

%Read csv with 15 header rows 
data = csvread(filename, 15); 

t = data(:,1); 
Vs1 = data(:,2); 
Vs2 = data(:,3); 

%Plot waveform 
figure 
    subplot(2,1,1); 
     plot(t,Vs1); 
     title('Sensor Input Measurements for 100pc Discharge '); 
     xlabel('Time[s]'); 
     ylabel('Voltage[V]'); 
     grid on; 
     grid minor; 

    subplot(2,1,2); 
     plot(t,Vs2); 
     title('Sensor Output Measurements for 100pc Discharge'); 
     xlabel('Time[s]'); 
     ylabel('Voltage[V]'); 
     grid on; 
     grid minor; 

end