Skip to main content
Fixed Quotes
Source Link
BlueMac
  • 721
  • 5
  • 13

I have groups of descriptive variable names and dont want to write explicit code for each group, e.g. (and this is a contrived simplification)

EnergySensorALow[1]=somefuncALow[#]& /@ lstSensorA; EnergySensorAHigh[1]=somefuncAHigh[#]& /@ lstSensorA; EnergySensorBLow[1]=somefuncALow[#]& /@ lstSensorB; EnergySensorBHigh[1]=somefuncAHigh[#]& /@ lstSensorB; 

etc.

I want create a function that should work as follows:

fnew[sensorType_String]:= "EnergySensor"+sensorType+"Low[1]="somefunc"+sensorType+"Low"[#]&"EnergySensor"+sensorType+"Low[1]"="somefunc"+sensorType+"Low"[#]& /@ "lstSensor"+sensorType; 

So the function will take an input String, e.g. "A" and then refer to an existing variable name EnergySensorALow[1], which it will set equal to an existing function somefuncALow[#]& and map this over an existing list lstSensorA

The code will also be run periodically when the sensor values update, and each time the function needs to be applied to the list and stored in the appropriate "EnergySensor" variable name. The variable index[n] makes it easy to use the data in a Manipulate and select which dataset needs to be plotted, I prefer not to add additional indexes to accomplish the functionality I need.

Any suggestions?

I have groups of descriptive variable names and dont want to write explicit code for each group, e.g. (and this is a contrived simplification)

EnergySensorALow[1]=somefuncALow[#]& /@ lstSensorA; EnergySensorAHigh[1]=somefuncAHigh[#]& /@ lstSensorA; EnergySensorBLow[1]=somefuncALow[#]& /@ lstSensorB; EnergySensorBHigh[1]=somefuncAHigh[#]& /@ lstSensorB; 

etc.

I want create a function that should work as follows:

fnew[sensorType_String]:= "EnergySensor"+sensorType+"Low[1]="somefunc"+sensorType+"Low"[#]& /@ "lstSensor"+sensorType; 

So the function will take an input String, e.g. "A" and then refer to an existing variable name EnergySensorALow[1], which it will set equal to an existing function somefuncALow[#]& and map this over an existing list lstSensorA

The code will also be run periodically when the sensor values update, and each time the function needs to be applied to the list and stored in the appropriate "EnergySensor" variable name. The variable index[n] makes it easy to use the data in a Manipulate and select which dataset needs to be plotted, I prefer not to add additional indexes to accomplish the functionality I need.

Any suggestions?

I have groups of descriptive variable names and dont want to write explicit code for each group, e.g. (and this is a contrived simplification)

EnergySensorALow[1]=somefuncALow[#]& /@ lstSensorA; EnergySensorAHigh[1]=somefuncAHigh[#]& /@ lstSensorA; EnergySensorBLow[1]=somefuncALow[#]& /@ lstSensorB; EnergySensorBHigh[1]=somefuncAHigh[#]& /@ lstSensorB; 

etc.

I want create a function that should work as follows:

fnew[sensorType_String]:= "EnergySensor"+sensorType+"Low[1]"="somefunc"+sensorType+"Low"[#]& /@ "lstSensor"+sensorType; 

So the function will take an input String, e.g. "A" and then refer to an existing variable name EnergySensorALow[1], which it will set equal to an existing function somefuncALow[#]& and map this over an existing list lstSensorA

The code will also be run periodically when the sensor values update, and each time the function needs to be applied to the list and stored in the appropriate "EnergySensor" variable name. The variable index[n] makes it easy to use the data in a Manipulate and select which dataset needs to be plotted, I prefer not to add additional indexes to accomplish the functionality I need.

Any suggestions?

Source Link
BlueMac
  • 721
  • 5
  • 13

Constructing variable names from a string

I have groups of descriptive variable names and dont want to write explicit code for each group, e.g. (and this is a contrived simplification)

EnergySensorALow[1]=somefuncALow[#]& /@ lstSensorA; EnergySensorAHigh[1]=somefuncAHigh[#]& /@ lstSensorA; EnergySensorBLow[1]=somefuncALow[#]& /@ lstSensorB; EnergySensorBHigh[1]=somefuncAHigh[#]& /@ lstSensorB; 

etc.

I want create a function that should work as follows:

fnew[sensorType_String]:= "EnergySensor"+sensorType+"Low[1]="somefunc"+sensorType+"Low"[#]& /@ "lstSensor"+sensorType; 

So the function will take an input String, e.g. "A" and then refer to an existing variable name EnergySensorALow[1], which it will set equal to an existing function somefuncALow[#]& and map this over an existing list lstSensorA

The code will also be run periodically when the sensor values update, and each time the function needs to be applied to the list and stored in the appropriate "EnergySensor" variable name. The variable index[n] makes it easy to use the data in a Manipulate and select which dataset needs to be plotted, I prefer not to add additional indexes to accomplish the functionality I need.

Any suggestions?