read multiple columns from an excel spreadsheet by using xlsread

조회 수: 94 (최근 30일)
Tatjana Mü
Tatjana Mü 2022년 3월 29일
댓글: Arif Hoq 2022년 3월 29일
Hi,
I have an Excel sheet with 300 columns, from which I just need several ranges. In a normal case I use the "import data" app. But this time it is not possible, because some of the strings are double. I just want to read in the first row and from this, several columns (all strings).
Just as an example:
I have a first row with strings like this:
x= ["'[23Na]+'" , "'[24Mg]+'" , "'[25Mg]+'" , "'[26Mg]+'" , "'[26Mg]++'" , "'[27Al]+'" , "'C2H3+'" , "'[28Si]+'"]
And now I just want to have A1:B1 and E1:F1. How do I use here xlsread with several ranges to end with a string like this:
x= ["'[23Na]+'" , "'[24Mg]+'" , "'[26Mg]++'" , "'[27Al]+'"]
I am grateful for every hint.

답변 (1개)

Arif Hoq
Arif Hoq 2022년 3월 29일
I guess you can not export multiple ranges data in Matlab.
Range must be of the form 'A1' (cell), 'A:B' (column-select), '1:5' (row-select), 'A1:B5' (rectangle-select), or a valid named range in the sheet.
Either you can export your data in multiple variable with range
A=readtable('example.xlsx','ReadVariableName',false,'Range','A1:B1');
B=readtable('example.xlsx','ReadVariableName',false,'Range','E1:F1');
or use readtable then process your data
  댓글 수: 4
Tatjana Mü
Tatjana Mü 2022년 3월 29일
@Arif Hoq Thank you so much. You seem to be quite familiar with matlab. Can I ask you another question? I have this line:
[num,txt,raw] = xlsread(filename{xy},'B1:KR1');
Do you know how I can add the delimiters here? And is it possible to have multiple delimiters? Because sometimes I have .csv files and sometimes .xlsx files.
Arif Hoq
Arif Hoq 2022년 3월 29일
maybe you are talking about file extension(.csv / .xlsx / .txt) not delimiters. As per i know you can define delimiters in text file (.txt). For excel or csv file readtable works efficiently as xlsread is not recommended. And i guess you can export either csv file or excel file once.
if you have further query please attach your code and data.It's better to suggest after that.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Spreadsheets에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by