Loading in Multiple Excel Files using readmatrix

조회 수: 10 (최근 30일)
Natalie Klueppelberg
Natalie Klueppelberg 2021년 3월 11일
댓글: Souarv De 2023년 5월 31일
Hi, I have this short code below but I am trying to import 5 excel files, names 101, 102, 103, 104 and 105.xlsx into matlab's workspace as separate cells so i can later make figures by calling on a column in each cell array.
They have the same number of columns (BS:BX) 6 columns is all I need but will have various rows. I'm new to MATLAB so maybe I am missing something easy here, it doesn't like the line "filename = (k,'%dtrf.xlsx');". "Invalid expression. When calling a function or indexing a variable, use parentheses. Otherwise, check for mismatched delimiters."
clear all
close all
mkdir myfolder
dir myfolder
for k = 101 : 105
filename = (k,'*.xlsx');
data = readmatrix(strcat(filename),'Range','BS:BX');
end
  댓글 수: 2
Mario Malic
Mario Malic 2021년 3월 12일
See this example https://matlab.fandom.com/wiki/FAQ#How_can_I_process_a_sequence_of_files.3F and MATLAB Onramp, it's great way to dive in MATLAB.
Natalie Klueppelberg
Natalie Klueppelberg 2021년 3월 12일
Thank you! I will read this now

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

답변 (1개)

Jan
Jan 2021년 3월 12일
Folder = 'C:\Your\Folder';
for k = 101 : 105
filename = fullfile(Folder, sprintf('%d.xlsx', k));
data = readmatrix(filename, 'Range', 'BS:BX');
...
end
  댓글 수: 2
Natalie Klueppelberg
Natalie Klueppelberg 2021년 3월 12일
Hi Jan, thanks for responding. That makes logical sense to me however it pops up with an error
"Error using readmatrix (line 149).
Unable to find or open
'C:/Users/natalie/Test/101.xlsx'.
Check the path and filename or file permissions.
Error in Test (line 7)
data = readmatrix(filename, 'Range', 'BS:BX');
Is this an issue using implying I need to use dir or fullfile?
Souarv De
Souarv De 2023년 5월 31일
@Natalie Klueppelberg Make sure whether the file you want to upload having .xlsx or .csv extension. You have to use the appropiate extension accordingly.

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

카테고리

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