hey assitent I have a lot of variable checks like this…
Jump to turn (7)
- 1hey assitent I have a lot of variable checks like this indiceRpmtorquemax=find(s
- 2is there an easier way?
- 3can I take directly the value without index?
- 4ok I will do with a function write me a function that give value that check
- 5No I want a functio like this vhData.Rpmtorquemax = function
- 6call that function for this indiceV1000BV1=find(strcmp(raw(:,1),'V1000BV1')); vh
- 7same for indiceEnergy=find(strcmp(raw(:,1),'Energy')); vhData.Energy=raw{indiceE
- User
hey assitent I have a lot of variable checks like this indice_Rpm_torque_max=find(strcmp(raw(:,1),'ICE_Rpm_torque_max')); vhData.Rpm_torque_max=raw{indice_Rpm_torque_max,2}; I want to get an check if index exists ( so is not []) than you can take the value, if not value is NaN
- Assistant
You can wrap your variable check in a conditional statement to handle the cases where the
findfunction returns an empty array. If the index exists (i.e., it's not empty), assign the value; otherwise, assignNaN. Here's how you can do it:matlabindice_Rpm_torque_max = find(strcmp(raw(:,1), 'ICE_Rpm_torque_max')); if ~isempty(indice_Rpm_torque_max) vhData.Rpm_torque_max = raw{indice_Rpm_torque_max, 2}; else vhData.Rpm_torque_max = NaN; end