Clear Filters
Clear Filters

xlsread in matlab app designer

5 views (last 30 days)
Hi I am trying to do xlsread in my matlab app designer. All I did was copy and paste:
series1=xlsread('Copy of Shaker Table Descaling Spreadsheet v10292018.xlsx',1)
series2=xlsread('Copy of Shaker Table Descaling Spreadsheet v10292018.xlsx',3)
series3=xlsread('Copy of Shaker Table Descaling Spreadsheet v10292018.xlsx',5)
rinse1=series1(18:26,1);
rinse2=series2(15:23,1);
rinse3=series3(15:23,1);
dM1=series1(18:26,2:end);
dM2=series2(15:23,2:end);
dM3=series3(15:23,2:end);
But it's giving me an error message: Invalid default value for property 'rinse1' in class 'descaling_app':
Undefined function 'series1' for input arguments of type 'double'.
  3 Comments
Stetson Spencer
Stetson Spencer on 21 Nov 2018
Well I was playing around with series1 earlier in the Matlab command window.
What I was trying to do is see which cells the data was going to be in once i put the excel cell format into matlab's cell format.
once I got the location of each data in each cell I just simply copied and pasted what you see up there under the properties (access=private) in the app designer code view

Sign in to comment.

Accepted Answer

Cris LaPierre
Cris LaPierre on 21 Nov 2018
Edited: Cris LaPierre on 21 Nov 2018
Under properties? That's the issue. I can now duplicate your error message.
Properties is for defining variables. If you want to run code, add it to a function. It can be a callback related to a button press or a helper function. If this is how you want things to start, consider placing it in the startupFcn Callback.
properties (Access = private)
series1;
rinse1;
dM1;
end
...
methods (Access = private)
% Button pushed function: Button
function ButtonPushed(app, event)
app.series1=xlsread('test.xlsx',1)
app.rinse1=app.series1(18:26,1);
app.dM1=app.series1(18:26,2:end);
end
end
If the variables are declared in Properties, they exist on the app structure and are passed into all functions. If you don't need them to be available outside the function, you could also just declare them within the function itself.
methods (Access = private)
% Button pushed function: Button
function ButtonPushed(app, event)
series1=xlsread('test.xlsx',1)
rinse1=series1(18:26,1);
dM1=series1(18:26,2:end);
end
end
Note that the code here executes in response to a button push in the app, so is added to the ButtonPushed callback function.

More Answers (1)

Guillaume
Guillaume on 21 Nov 2018
Edited: Guillaume on 21 Nov 2018
You probably need to learn a bit more about class design in matlab. Indeed, the code you have written cannot be put in the properties section of the class definition. You are in effect declaring the class properties with some default values, but as documented, expressions for default values cannot reference other variables.
A better design would be to have, in the properties section, just:
properties (Access = private)
series1;
series2;
series3;
rinse1;
rinse2;
rinse3;
dM1;
dM2;
dM3;
end
and then add a startup function to your app with:
function startupFcn(app)
app.series1=xlsread('Copy of Shaker Table Descaling Spreadsheet v10292018.xlsx',1)
app.series2=xlsread('Copy of Shaker Table Descaling Spreadsheet v10292018.xlsx',3)
app.series3=xlsread('Copy of Shaker Table Descaling Spreadsheet v10292018.xlsx',5)
app.rinse1=series1(18:26,1);
app.rinse2=series2(15:23,1);
app.rinse3=series3(15:23,1);
app.dM1=series1(18:26,2:end);
app.dM2=series2(15:23,2:end);
app.dM3=series3(15:23,2:end);
end
And since numbered variables are a bad design, even better would be:
properties (Access = private)
series;
rinse;
dM;
end
function startupFcn(app)
%constants
sheets = [1; 3; 5]
ranges = [18 26; 15 23; 15 23];
%initialisation
app.series = cell(size(sheets));
app.rinse = cell(size(sheets));
app.dM = cell(size(sheets))
%loading
for i = 1:numel(sheets)
app.series{i} = xlsread('Copy of Shaker Table Descaling Spreadsheet v10292018.xlsx', sheets(i))
app.rinse{i} = series{i}(ranges(i, 1):ranges(i, 2), 1);
app.dM{i} = series{i}(ranges(i, 1):ranges(i, 2), 2:end);
end
end
This latter approach has the advantage that if you want to add series, you don't have to modify the code, just edit the two constants sheets and ranges.

Categories

Find more on Cell Arrays in Help Center and File Exchange

Products


Release

R2018b

Community Treasure Hunt

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

Start Hunting!