Why is it not possible to increase the excel readtable range?

조회 수: 1(최근 30일)
Dursman Mchabe
Dursman Mchabe 2021년 9월 26일
댓글: dpb 2021년 9월 28일
Hi Everyone,
Why is it not possible to increase the excel read table range in my case?
I have an excel spreadsheet (attached) from which I am extracting data.
My challange is, I can only work with fixed range (A1: AG88),
When I try adding a column on the excel file, and try, A1:AH88, I get the following error message:
Error using MathsWorksQuestion (line 81)
Using '.Variables' with more than one level of subscripting is not supported. Use brace subscripting directly on the
table instead.
The code I am using is
%% Initialize and read data from Excel
RawData = readtable('ExperimentalDatabase.xlsx','Range','A1:AH88');
%% Extract experiments data
% Create a structure called "Chips"
% ==> fields in the structure will be given "fields_names"
% ==> field names will corresponds to extraction pressure
% ==> Namely:
% Chips.Entrapped_0 corresponds to free liquor
% Chips.Entrapped_1 corresponds to an extraction pressure of 2.5 tons
% Chips.Entrapped_2 corresponds to an extraction pressure of 5 tons
% Chips.Entrapped_3 corresponds to an extraction pressure of 8 tons
field_names = {'FreeLiquor','Entrapped_1','Entrapped_2','Entrapped_3'};
extraction_pressure = [0, 2.5, 5 , 8];
% Create a cycle for chips results at different extraction pressures
for l = 1:length(extraction_pressure)
% index raw data for every particle size classified as chips
index = find(strcmp(RawData.ParticleSize,'Chips')... % for every extraction pressure
.*(RawData.EntrappedLiquorSqueezing_tons_ == extraction_pressure(l)));
% Create a "Temp" for all the chips' subset data of interest
Temp = RawData(index,:);
% Organize data the best way it will suite your needs, e.g.:
% Time : write "cooking time" into a vector
Chips.(field_names{l}).Time = Temp.CookingTime_min_;
% Constant data : Save data that stays constant in a "Description" structure
Chips.(field_names{1}).Description = struct('T', Temp.CookingTemperature__C_(1), ...
'P', Temp.CookingPressure_bar_(1), ...
'WoodMass', Temp.WoodMass_g_(1), ...
'SteamMass', Temp.SteamMass_g_(1), ...
'Na2SO3ODWBasis', Temp.Na2SO3ODWBasis___(1), ...
'Na2CO3ODWBasis', Temp.Na2CO3ODWBasis___(1),...
% Redundent variables in Temp: Remove them
Temp = removevars(Temp,{'Date',...
'Na2CO3ODWBasis___', ...
'CookingTime_min_', ...
'CookingPressure_bar_', ...
% Field names of interest: save them in "fields"
fields = fieldnames(Temp);
% Less important field names: remove them
fields([1, 21, 22, 23]) = [];
% Find main experiments, i.e. when Repeat_ = 0
Rep0 = find(Temp.Repeat_ == 0);
% Experiments associated with specific times
for i = 1: length(Rep0)
% Find all repeats associated with specific time
k = find(Chips.(field_names{l}).Time == Chips.(field_names{l}).Time(Rep0(i)));
% Create fields
for j = 1:length(fields)
% Cell array containing individual values
Chips.(field_names{l}).Repeats.(fields{j}){i} = Temp.(fields{j})(k);
% Try a mean
Chips.(field_names{l}).Mean.(fields{j})(i) = mean(Temp.(fields{j})(k));
% Try a standard deviation
Chips.(field_names{l}).STD.(fields{j})(i) = std(Temp.(fields{j})(k));
% Remove redunandant time points
Chips.(field_names{l}).Time = unique(Chips.(field_names{l}).Time);
  댓글 수: 2
Dursman Mchabe
Dursman Mchabe 2021년 9월 27일
I think I misunderstood the problem.

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

채택된 답변

dpb 2021년 9월 27일
The error message doesn't have anything to do with the Q? that was posed as written and looked at above, however...it's got to do with the line
Chips.(field_names{l}).Repeats.(fields{j}){i} = Temp.(fields{j})(k);
It fails for j=20 because the name 'Variables' which is the value of the last element of both the field_names and fields arrays doesn't exist in either the Chips struct nor the Temp table.
  댓글 수: 2
dpb 2021년 9월 28일
Well, the code is so convoluted I've not tried to figure out the logic in what it is it's trying to do, specifically, but the two arrays containing field names of the stuct and the the table will have to have element values that are actually in the two.
The problem isn't the value of the index, it's the content of the arrays. Reorder the two arrays as they currently are to put the string 'Variables' first and it'll fail on the first pass instead of the last with the same error message...so,you can have j be as large as you wish but IFF (if and only if) all the variables are extant in both.

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

추가 답변(0개)


Community Treasure Hunt

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

Start Hunting!

Translated by