gpt4 book ai didi

excel - 如何让 MATLAB xlsread 读取到连续 <> 的最后一行?

转载 作者:行者123 更新时间:2023-12-04 22:04:34 27 4
gpt4 key购买 nike

我想使用 xlsread在 MATLAB 中读取 Excel 文件。

虽然我知道要读取哪些列以及要从哪一行开始读取,但该文件可以包含任意数量的行。

有没有办法像 :

array = xlsread( 'filename', 'D4:F*end*' );              %% OR ANY SIMILAR SYNTAX

在哪里 F*end* 是 F 列的最后一行吗?

最佳答案

是的。尝试这个:

FileFormat = '.xls' or '.xlsx';                         % choose one
% ( by default MATLAB
% imports only '.xls' )
filename = strcat( 'Filename you desire', FileFormat );

array = xlsread( filename ) % This will read all
% the Matrix ( by default
% MATLAB will import all
% numerical data from
% file with this syntax )

然后您可以查看矩阵的大小以优化搜索/导入。
[nRows,nCols] = size( array );

然后,如果您只想导入矩阵的一部分,您可以这样做:
NewArray = xlsread( filename, strcat( 'initial cell',
':',
'ColumnLetter',
num2str( nRows )
)
);
% for your case:

NewArray = xlsread( filename, strcat( 'D3', ':', 'F', num2str( nRows ) ) );

希望这可以帮助。

关于excel - 如何让 MATLAB xlsread 读取到连续 <<data-range>> 的最后一行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26765747/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com