Cell Array Dynamic Size

6 views (last 30 days)
XC
XC on 25 Jul 2019
Edited: XC on 20 Aug 2019
Any thoughts would be helpful!

Accepted Answer

Are Mjaavatten
Are Mjaavatten on 25 Jul 2019
If you are happy with storing the data as a matrix for each sheet :
filename = 'Q.xlsx';
n_sheets = 2;
DP = cell(1,n_sheets); % Store data in cell arrays
for i = 1:n_sheets
sheet = ['DP ',num2str(i-1)];
DP{i} = xlsread(filename,sheet);
end
The data for time step k on the second data sheet (DP 1) is now:
DP{2}(17,:)
Variables are stored column-wise, as in the Excel sheet
plot(DP{2}(:,2))
If you want a more flexible data representation, you may create a Matlab struct for each sheet:
for i = 1:n_sheets
sheet = ['DP ',num2str(i-1)];
numdata = xlsread(filename,sheet);
[~,headers] = xlsread(filename,sheet,'A1:M1');
% Create fields for each column:
DP{i}.time = numdata(:,1);
for j = 2:length(headers)
parts = regexp(headers{j},'\s','split'); % Extract the relevant string
varname = parts{3};
DP{i}.(varname) = numdata(:,j);
end
end
plot(DP{2}.time,DP{2}.Fx1)

More Answers (0)

Products


Release

R2016b

Community Treasure Hunt

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

Start Hunting!