startrow matlab,I have to detect the Startrow and endrow from a file automatically from a .txt file....

这是一个MATLAB脚本,用于从文本文件中导入数据。它读取指定行范围内的数据,并将数据分配给变量Time、Displacement和ForceZ。脚本使用textscan函数处理以制表符分隔的数据,并处理可能的空值。脚本还包含了检查首字母以决定是否读取数据的注释说明。
摘要由CSDN通过智能技术生成

function [Time,Displacement,ForceZ] = importfile1(fileName) %IMPORTFILE1 Import numeric data from a text file as column vectors. % [DATE1,TUEJUL082014,VARNAME3] = IMPORTFILE1(FILENAME) Reads data from % text file FILENAME for the default selection. % % [DATE1,TUEJUL082014,VARNAME3] = IMPORTFILE1(FILENAME, STARTROW, ENDROW) % Reads data from rows STARTROW through ENDROW of text file FILENAME. % % Example: % [Date1,TueJul082014,VarName3] = importfile1('RELAXATION.txt',23, % 12107); % % See also TEXTSCAN.

% Auto-generated by MATLAB on 2014/07/17 12:07:48

%% Initialize variables. delimiter = '\t'; if nargin<=2 startRow = 26; endRow = 30742; end

%% Format string for each line of text: % column1: text (%s) % column2: text (%s) % column3: text (%s) % For more information, see the TEXTSCAN documentation. formatSpec = '%s%s%s%[^\n\r]';

%% Open the text file. fileID = fopen(fileName,'r');

%% Read columns of data according to format string. % This call is based on the structure of the file used to generate this % code. If an error occurs for a different file, try regenerating the code % from the Import Tool. dataArray = textscan(fileID, formatSpec, endRow(1)-startRow(1)+1, 'Delimiter', delimiter, 'EmptyValue' ,NaN,'HeaderLines', startRow(1)-1, 'ReturnOnError', false); for block=2:length(startRow) frewind(fileID); dataArrayBlock = textscan(fileID, formatSpec, endRow(block)-startRow(block)+1, 'Delimiter', delimiter, 'EmptyValue' ,NaN,'HeaderLines', startRow(block)-1, 'ReturnOnError', false); for col=1:length(dataArray) dataArray{col} = [dataArray{col};dataArrayBlock{col}]; end end

%% Close the text file. fclose(fileID);

%% Post processing for unimportable data. % No unimportable data rules were applied during the import, so no post % processing code is included. To generate code which works for % unimportable data, select unimportable cells in a file and regenerate the % script.

%% Allocate imported array to column variable names Time = dataArray{:, 1}; Displacement = dataArray{:, 2}; ForceZ = dataArray{:, 3}; TimeMat=str2double(Time(:,1)); ForceMat=str2double(ForceZ(:,1)); DispMat=str2double(Displacement(:,1));

This is the program ....and the file from which i have to extract the data...... #

What i want to do is 1. i want the program to start reading the data from the line where the readings start.

2. so my idea is is to write a code which checks every line for it's first letter ,as whether a alphabet or number.... if it is a alphabet it should not take the vale and the vise versa.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值