xls read multiple files into one script; Only reading last file
1 次查看(过去 30 天)
显示 更早的评论
I am trying to add multiple .xls files into Matlab and plot some data against time. The first file contains data for one hour of time, the second file contains data for the second hour of time and so on. I want each file to build off of the previous file. Each file contains the same column headers in the first row. When I read multiple files into the script, it only loads the last file I select.
[file_list,path_n] = uigetfile('.xlsx','Grab the files you want','Multiselect','on');
if iscell(file_list) == 0
file_list = [file_list];
end
for i = 1:length(file_list)
filename = file_list{i};
data_in = xlsread([path_n filename]);
alldata = data_in(:,:);
end
Time = alldata(:,2);
Position_Rev = alldata(:,3);
Current = alldata(:,8);
Voltage = alldata(:,9);
Altitude = alldata(:,162);
Motor_Speed = alldata(:,4);
date_time = datetime(Time,'ConvertFrom','epochtime','TicksPerSecond',1e3,'Format','dd-MMM-yyyy HH:mm:ss.SSS');
figure(1)
yyaxis left
plot(date_time,Motor_Speed)
xlabel('Time','FontWeight','bold','Fontsize',12);
ylabel('Motor Speed','FontWeight','bold','Fontsize',12);
hold on
yyaxis right
plot(date_time,Current)
ylabel('Current','FontWeight','bold','Fontsize',12);
title('Time vs. Motor Speed','FontWeight','bold','Fontsize',12);
0 个评论
回答(1 个)
Image Analyst
2022-1-10
You're overwriting alldata each time. You probably want to append onto it. Instead of
alldata = data_in(:,:); % Overwrite alldata with data_in.
do
alldata = [alldata; data_in]; % Append data_in to alldata.
Be sure to initialize alldata before the loop
alldata = [];
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!