How to create a uitable from extracted data from a struct in app designer?

8 次查看(过去 30 天)
I am having some trouble with creaating a uitable from the extracted data from a struct in app designer. I first coded this:
datafile = fullfile('\\fl51s01\ClearwaterEngrg\CETLab','AccelQuery.mat');
rmdData=load(datafile)
rmdDatanames=fieldnames(rmdData)
SERIAL_NUMBER=cellfun(@(SERIAL_NUMBER)(rmdData.(SERIAL_NUMBER)),fieldnames(rmdData))
BIA_COF_0=cellfun(@(BIA_COF_0)(rmdData.(BIA_COF_0)),fieldnames(rmdData))
BIA_COF_1=cellfun(@(BIA_COF_1)(rmdData.(BIA_COF_1)),fieldnames(rmdData))
BIA_COF_2=cellfun(@(BIA_COF_2)(rmdData.(BIA_COF_2)),fieldnames(rmdData))
BIA_COF_3=cellfun(@(BIA_COF_3)(rmdData.(BIA_COF_3)),fieldnames(rmdData))
BIA_COF_4=cellfun(@(BIA_COF_4)(rmdData.(BIA_COF_4)),fieldnames(rmdData))
SF_COF_0=cellfun(@(SF_COF_0)(rmdData.(SF_COF_0)),fieldnames(rmdData))
SF_COF_1=cellfun(@(SF_COF_1)(rmdData.(SF_COF_1)),fieldnames(rmdData))
SF_COF_2=cellfun(@(SF_COF_2)(rmdData.(SF_COF_2)),fieldnames(rmdData))
SF_COF_3=cellfun(@(SF_COF_3)(rmdData.(SF_COF_3)),fieldnames(rmdData))
SF_COF_4=cellfun(@(SF_COF_4)(rmdData.(SF_COF_4)),fieldnames(rmdData))
In an effort to extract the values from the fields of the struct. I then coded:
mergetables=struct2array({SERIAL_NUMBER,BIA_COF_0,BIA_COF_1,BIA_COF_2,BIA_COF_3...
,BIA_COF_4,SF_COF_0,SF_COF_1,SF_COF_2,SF_COF_3,SF_COF_4});
uidata=uitable(uifigure,'Data',{mergetables});
uitdata.ColumnName={'Accel S/N' ;'BIA_COF_0'; 'BIA_COF_1'; 'BIA_COF_2'; 'BIA_COF_3' ;'BIA_COF_4';...
'SF_COF_0'; 'SF_COF_1'; 'SF_COF_2' ;'SF_COF_3' ;'SF_COF_4'};
I then got an error for mergetables:
Undefined function 'struct2cell' for input arguments of type 'cell'.
Error in struct2array (line 10)
c = struct2cell(s);
Any suggestions or resolutions to apply?

回答(1 个)

Jalaj Gambhir
Jalaj Gambhir 2020-8-26
Hi,
The issue is occuring because you are passing cell arguments to the function. As you are converting from struct, the input arguments must be struct. Look at the examples that might guide you.
Hope this helps.

类别

Help CenterFile Exchange 中查找有关 Workspace Variables and MAT-Files 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by