フィルターのクリア

How to Load .mat file into app designer to Plot?

11 ビュー (過去 30 日間)
Subathra Nilamegan
Subathra Nilamegan 2023 年 11 月 26 日
回答済み: Walter Roberson 2023 年 11 月 27 日
Can anyone let me know what is wrong in these codes? The error is
Unrecognized field name "VarName1"
%starting plot
%Load Data
data1 = load('SBC1.mat', 'VarName1', 'VarName2');
BD1 = data1.VarName1;
SD1 = data1.VarName2;
data2 = load('SBC2.mat', 'VarName1', 'VarName2');
BD2 = data2.VarName1;
SD2 = data2.VarName2;
data3 = load('SBC3.mat', 'VarName1', 'VarName2');
BD3 = data3.VarName1;
SD3 = data3.VarName2;
data4 = load('SBC4.mat', 'VarName1', 'VarName2');
BD4 = data4.VarName1;
SD4 = data4.VarName2;
% Remove duplicate x values and smooth lines for all data sets
[xUnique1, idxUnique1] = unique(BD1);
yUnique1 = SD1(idxUnique1);
[xUnique2, idxUnique2] = unique(BD2);
yUnique2 = SD2(idxUnique2);
[xUnique3, idxUnique3] = unique(BD3);
yUnique3 = SD3(idxUnique3);
[xUnique4, idxUnique4] = unique(BD4);
yUnique4 = SD4(idxUnique4);
  5 件のコメント
Subathra Nilamegan
Subathra Nilamegan 2023 年 11 月 27 日
what do you mean by this? can you explain a bit?
SBC1.Properties.VariableNames
SBC2.Properties.VariableNames
SBC3.Properties.VariableNames
SBC4.Properties.VariableNames
Walter Roberson
Walter Roberson 2023 年 11 月 27 日
data1 = load('SBC1.mat');
That command loads all of the variables stord in SBC1.mat, and creates a scalar struct named data1 that has one field for each variable stored in SBC1.mat .
According to your earlier response https://www.mathworks.com/matlabcentral/answers/2052197-how-to-load-mat-file-into-app-designer-to-plot#comment_2976257 each of your .mat files contains a single variable such as SBC1
SBC1 = data1.SBC1;
That pulls out the field named SBC1 from the struct array that was just created by the load(), and assigns it to the variable SBC1 . According to the output you posted, SBC1 would then be a table object.
Table objects have several meta-data properties that describe the contents of the table. For example each variable can have a description field. The meta-data properties of an individual table can be accessed by examining the Properties property of the table object.
One of the properties that is stored is the list of variable names.
So when SBC1 is the name of a table object, then SBC1.Properties.VariableNames will output a list of the names of the variables stored in the table.
SBC1.Properties.VariableNames
SBC2.Properties.VariableNames
SBC3.Properties.VariableNames
SBC4.Properties.VariableNames
is code that will output the variable names stored in each of the tables SBC1, SBC2, SBC3, SBC4

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

回答 (1 件)

Walter Roberson
Walter Roberson 2023 年 11 月 27 日
Based on things you are posting in other questions, I think what you are looking for is
%starting plot
%Load Data
data1 = load('SBC1.mat', 'VarName1', 'VarName2');
BD1 = data1.SBC1.VarName1;
SD1 = data1.SBC1.VarName2;
data2 = load('SBC2.mat', 'VarName1', 'VarName2');
BD2 = data2.SBC2.VarName1;
SD2 = data2.SBC2.VarName2;
data3 = load('SBC3.mat', 'VarName1', 'VarName2');
BD3 = data3.SBC3.VarName1;
SD3 = data3.SBC3.VarName2;
data4 = load('SBC4.mat', 'VarName1', 'VarName2');
BD4 = data4.SBC4.VarName1;
SD4 = data4.SBC4.VarName2;
% Remove duplicate x values and smooth lines for all data sets
[xUnique1, idxUnique1] = unique(BD1);
yUnique1 = SD1(idxUnique1);
[xUnique2, idxUnique2] = unique(BD2);
yUnique2 = SD2(idxUnique2);
[xUnique3, idxUnique3] = unique(BD3);
yUnique3 = SD3(idxUnique3);
[xUnique4, idxUnique4] = unique(BD4);
yUnique4 = SD4(idxUnique4);

カテゴリ

Help Center および File ExchangeDevelop Apps Using App Designer についてさらに検索

製品


リリース

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by