フィルターのクリア

Importing Excel file and reading data

1 回表示 (過去 30 日間)
Alex Burbee
Alex Burbee 2019 年 7 月 31 日
回答済み: Alex Burbee 2019 年 8 月 2 日
I am trying to read in about 90 excel files and read in various temperatures and pressures for each excel file. Meaning, I want to log and plot Run 1 with Pressure 1 and temp 1, Run 2 with pressure 2 and temp 2, etc. How do i get the code below to add the run numbder after the B1P('instert run number here')
%Open and Read the Excel File
D = 'C:\Users\test';
S = dir(fullfile(D,'*.xlsx'));
for k = 1:numel(S)
F = fullfile(D,S(k).name);
numdata1 = xlsread(F);
opts=detectImportOptions(F);
opts.VariableNamesRange='A5';
opts.DataRange='A6';
%import your desired data
B1P1 = numdata1(:,18)
A1P1 = numdata1(:,15)
B2P1 = numdata1(:,19)
A2P1 = numdata1(:,16)
B3P1 = numdata1(:,20)
end
  4 件のコメント
Walter Roberson
Walter Roberson 2019 年 7 月 31 日
Leave out those three lines.
I do not understand how you want the run numbers to be used.
Alex Burbee
Alex Burbee 2019 年 7 月 31 日
編集済み: Alex Burbee 2019 年 7 月 31 日
I want the run number to be stated after the Pressure
So Run 1 would yield
A1P1
A2P1
A3P1
Run 2 would yeild
A1P2
A2P2
A3P2

サインインしてコメントする。

採用された回答

Alex Burbee
Alex Burbee 2019 年 8 月 2 日
I ended up doing the following
D = 'Testlocation';
S = dir(fullfile(D,'*.xlsx'));
B1P = {}
B2P = {}
%...
for k = 1:numel(S)
F = fullfile(D,S(k).name);
numdata1 = xlsread(F);
opts=detectImportOptions(F);
opts.VariableNamesRange='A5';
opts.DataRange='A6';
%import your desired data
B1P{k} = numdata1(:,18)
A1P{k} = numdata1(:,15)
B2P{k} = numdata1(:,19)

その他の回答 (1 件)

Sulaymon Eshkabilov
Sulaymon Eshkabilov 2019 年 7 月 31 日
Hi,
Here is the simple solution to your problem:
D = 'C:\Users\test'; % Directory where all data: Run1.xls, Run2.xls, ... stored
N = 90; % Number of data files to read/load
DATA_ALL =cell(1, N); % Memory allocation
%Pressure = zeros( ??, 90); % Memory allocation
%Temperature = zeros(???, 90); % Memory allocation
for k = 1:N
Filename = sprintf('RUN_%d.xls', ii);
DATA = xlsread(Filename);
DATA_ALL{k} = DATA; % All read data saved in cell
Pressure(:, k) = DATA(:,1); % 1st column is pressure
Temperature(:,k)= DATA(:,2); % 2nd colum is temperature
% plot(Pressure(:,k), Temperature(:,k)), hold all % To see the plots from each logged data
end
Good luck

カテゴリ

Help Center および File ExchangeSpreadsheets についてさらに検索

製品


リリース

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by