xlsread in matlab app designer
10 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
採用された回答
Cris LaPierre
2018 年 11 月 21 日
編集済み: Cris LaPierre
2018 年 11 月 21 日
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.
0 件のコメント
その他の回答 (1 件)
Guillaume
2018 年 11 月 21 日
編集済み: Guillaume
2018 年 11 月 21 日
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
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.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Develop Apps Using App Designer についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!