xlsread in matlab app designer
이전 댓글 표시
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일
Is the xlsx file in the same folder as your app? Actually, that would give a different obvious error message. It's complaining about the value assigned to rinse1 and it thinks series1 is a function.
Have you defined series1 or rinse1 anywhere else?
Stetson Spencer
2018년 11월 21일
Stetson Spencer
2018년 11월 21일
채택된 답변
추가 답변 (1개)
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.
카테고리
도움말 센터 및 File Exchange에서 Spreadsheets에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!