Getting structure content using strings

1 次查看(过去 30 天)
I have kt containing data type "strings", one of them is "grad"i.e kt(1,1)=grad which is a string. I am also trying to get the content of the structure(Data.edata.grad) in my data using the string data set by doing Data.edata.kt(1,1) but i am getting the error kt(1,1) is not an existing field. How can i convert a string to a structure or how can i use my string data set to get the structures?
  3 个评论
samuel okeleye
samuel okeleye 2018-8-11
编辑:Walter Roberson 2018-8-11
clear;
clc;
load('Unit 1001 Session 0068.mat')
k=Data.ECU_Data;
m=Data.Continuous_Data;
%CREATING THE FIELDS THAT NEED TO BE CHECKED
fieldcheck={'spn00084_src00_wheel_based_vehicle_speed';...
'spn00190_src00_engine_speed';...
'spn00102_src00_engine_intake_manifold_1_pressure';...
'spn00105_src00_engine_intake_manifold_1_temperature';...
'spn00108_src00_barometric_pressure';...
'spn00513_src00_actual_engine___percent_torque';...
'spn00110_src00_engine_coolant_temperature';...
'spn00183_src00_engine_fuel_rate';...
'spn00514_src00_nominal_friction___percent_torque';...
'spn00528_src00_engine_speed_at_point_2_engine_configuration';...
'spn00529_src00_engine_speed_at_point_3_engine_configuration';...
'spn00530_src00_engine_speed_at_point_4_engine_configuration';...
'spn00531_src00_engine_speed_at_point_5_engine_configuration';...
'spn00540_src00_engine_percent_torque_at_point_2_engine_configur';...
'spn00541_src00_engine_percent_torque_at_point_3_engine_configur';...
'spn00542_src00_engine_percent_torque_at_point_4_engine_configur';...
'spn00543_src00_engine_percent_torque_at_point_5_engine_configur';...
'spn00544_src00_engine_reference_torque_engine_configuration';...
'spn04154_src00_actual_engine___percent_torque_high_resolution';...
'spn03700_src00_diesel_particulate_filter_active_regeneration_st'};
fieldcheck2={'ambient.temperature';...
'vehicle.speed.gps';...
'vehicle.position.latitude';...
'vehicle.position.longitude';...
'vehicle.position.altitude'};
%%Channel Existence Check
af1=isfield(k,{'spn00084_src00_wheel_based_vehicle_speed';...
'spn00190_src00_engine_speed';...
'spn00102_src00_engine_intake_manifold_1_pressure';...
'spn00105_src00_engine_intake_manifold_1_temperature';...
'spn00108_src00_barometric_pressure';...
'spn00513_src00_actual_engine___percent_torque';...
'spn00110_src00_engine_coolant_temperature';...
'spn00183_src00_engine_fuel_rate';...
'spn00514_src00_nominal_friction___percent_torque';...
'spn00528_src00_engine_speed_at_point_2_engine_configuration';...
'spn00529_src00_engine_speed_at_point_3_engine_configuration';...
'spn00530_src00_engine_speed_at_point_4_engine_configuration';...
'spn00531_src00_engine_speed_at_point_5_engine_configuration';...
'spn00540_src00_engine_percent_torque_at_point_2_engine_configur';...
'spn00541_src00_engine_percent_torque_at_point_3_engine_configur';...
'spn00542_src00_engine_percent_torque_at_point_4_engine_configur';...
'spn00543_src00_engine_percent_torque_at_point_5_engine_configur';...
'spn00544_src00_engine_reference_torque_engine_configuration';...
'spn04154_src00_actual_engine___percent_torque_high_resolution';...
'spn03700_src00_diesel_particulate_filter_active_regeneration_st'});
af2=isfield(m,{'ambient.temperature';...
'vehicle.speed.gps';...
'vehicle.position.latitude';...
'vehicle.position.longitude';...
'vehicle.position.altitude'});
%Available and Unavailable Channels
af1av=fieldcheck(af1==1);
af1unav=fieldcheck(af1==0);
%
af2av=fieldcheck2(af2==1);
af2unav=fieldcheck2(af2==0);
avk=k.af1av
Error
Reference to non-existent field 'af1av'.
Error in QA_QC (line 86)
avk=k.af1av;
samuel okeleye
samuel okeleye 2018-8-11
I switched the string to cell for simplicity.

请先登录,再进行评论。

采纳的回答

Walter Roberson
Walter Roberson 2018-8-11
Data.edata.(kt(1,1))
You might perhaps need to use
Data.edata.(kt{1,1})
  5 个评论
Walter Roberson
Walter Roberson 2018-8-11
That code relies upon the fields all being the same datatype and all scalars (either numeric scalars or scalar logical or scalar character or scalar cell array.)

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Structures 的更多信息

产品


版本

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by