필터 지우기
필터 지우기

Getting structure content using strings

조회 수: 1 (최근 30일)
samuel okeleye
samuel okeleye 2018년 8월 10일
댓글: samuel okeleye 2018년 8월 11일
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.)
samuel okeleye
samuel okeleye 2018년 8월 11일
Thank you.

댓글을 달려면 로그인하십시오.

추가 답변 (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