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

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 Comments

Please show us the output of
whos -file SBC1.mat
whos -file SBC2.mat
whos -file SBC3.mat
whos -file SBC4.mat
This is the output.
>> whos -file SBC1.mat
whos -file SBC2.mat
whos -file SBC3.mat
whos -file SBC4.mat
Name Size Bytes Class Attributes
SBC1 - 2111 table
Name Size Bytes Class Attributes
SBC2 - 2143 table
Name Size Bytes Class Attributes
SBC3 - 2127 table
Name Size Bytes Class Attributes
SBC4 - 2127 table
data1 = load('SBC1.mat');
SBC1 = data1.SBC1;
data2 = load('SBC2.mat');
SBC2 = data2.SBC2;
data3 = load('SBC3.mat');
SBC3 = data3.SBC3;
data4 = load('SBC4.mat');
SBC4 = data4.SBC4;
Then having done that please show
SBC1.Properties.VariableNames
SBC2.Properties.VariableNames
SBC3.Properties.VariableNames
SBC4.Properties.VariableNames
what do you mean by this? can you explain a bit?
SBC1.Properties.VariableNames
SBC2.Properties.VariableNames
SBC3.Properties.VariableNames
SBC4.Properties.VariableNames
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

Sign in to comment.

Answers (1)

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);

Categories

Find more on Develop Apps Using App Designer in Help Center and File Exchange

Products

Release

R2023b

Asked:

on 26 Nov 2023

Answered:

on 27 Nov 2023

Community Treasure Hunt

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

Start Hunting!