A table variable name subscript must be a character vector

What does my error mean? i am trying to upload a ".xls" file using "add button"and transfer the data into a table and "add button" will calculate for stress and strain and plot in UI.axes
% Button pushed function: AddButton
function AddButtonPushed(app, event)
strain = app.StrainEditField.Value;
stress = app.StressEditField.Value;
nr = {strain, stress};
app.UITable.Data = [app.t;nr];
end
% Button pushed function: PlotButton
function PlotButtonPushed(app, event)
app.t = readtable('BlankSheet.xlsx','Sheet',1);
strain = table2array(app.t(:,"")); %A table variable name subscript must be a character vector, string array, or cell array of character vectors.
stress = table2array(app.t(:,""));
plot(app.UIAxes,strain,stress);
end
end

 採用された回答

Ameer Hamza
Ameer Hamza 2020 年 4 月 30 日

0 投票

You need to write the name of column
strain = table2array(app.t(:,"strain_column_name")); %A table variable name subscript must be a character vector, string array, or cell array of character vectors.
stress = table2array(app.t(:,"stress_column_name"));
Also, you can avoid table2array to array by using brace indexing
strain = app.t{:,"strain_column_name"}; %A table variable name subscript must be a character vector, string array, or cell array of character vectors.
stress = app.t{:,"stress_column_name"};

4 件のコメント

sydney salvador
sydney salvador 2020 年 5 月 1 日
編集済み: sydney salvador 2020 年 5 月 1 日
I am sorry I do not know the name of my column or how/where to place a name for it, this is the file i use
I only have a name for the whole table
properties (Access = private)
t % Table to share between callbacks
end
Ameer Hamza
Ameer Hamza 2020 年 5 月 1 日
編集済み: Ameer Hamza 2020 年 5 月 1 日
sydney, columns in MATLAB tables must have a name. If you don't specify, then still MATLAB gives them a default name. For example, when I run these lines using your file
t = readtable('BlankSheet.xlsx','Sheet',1);
disp(t)
Var1 Var2
____ ____
0 2
5 2
6 4
The column names are Var1 and Var2. If the column had names in excel files, then MATLAB would have used those names. So to access the first Var1 column, you need to write it like this
strain = t{:,"Var1"};
stress = t{:,"Var2"};
You can also directly use the column number if you are confused about the name of column
strain = t{:,1};
stress = t{:,2};
Walter Roberson
Walter Roberson 2020 年 5 月 1 日
t{:, 2} for stress
Ameer Hamza
Ameer Hamza 2020 年 5 月 1 日
Thanks for pointing out.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeStress and Strain についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by