Quantcast
Channel: Active questions tagged units - Mathematica Stack Exchange
Viewing all articles
Browse latest Browse all 41

Cases syntax when expression sought is a Quantity

$
0
0

From the following list I wish to extract those cases for which the magnitude of a quantity is greater than zero for which I would like to then create a DateListPlot.

 list = {{DateObject[{2017, 01}, "Month"], Quantity[0.00, "Dollars"]},         {DateObject[{2017, 02}, "Month"], Quantity[681.00, "Dollars"]},         {DateObject[{2017, 03}, "Month"], Quantity[681.00, "Dollars"]},         {DateObject[{2017, 04}, "Month"], Quantity[704.00, "Dollars"]},         {DateObject[{2017, 05}, "Month"], Quantity[0.00, "Dollars"]},         {DateObject[{2017, 06}, "Month"], Quantity[0.00, "Dollars"]},         {DateObject[{2017, 07}, "Month"], Quantity[0.00, "Dollars"]},         {DateObject[{2017, 08}, "Month"], Quantity[704.00, "Dollars"]},         {DateObject[{2017, 09}, "Month"], Quantity[0.00, "Dollars"]},         {DateObject[{2017, 10}, "Month"], Quantity[970.80, "Dollars"]},         {DateObject[{2017, 11}, "Month"], Quantity[0.00, "Dollars"]},         {DateObject[{2017, 12}, "Month"], Quantity[704.00, "Dollars"]}}

However, using the following expression and variations I can't seem to create an appropriate syntax. Instead creating a DateListPlot for a sublist with those elements for which the QuantityMagnitude is greater than zero, I get the error: "Quantity::unkunit: Unable to interpret unit specification {Automatic,Automatic}".

 DateListPlot[Cases[list, {_, x_} && QuantityMagnitude[x] > 0]]

The following doesn't work either:

 DateListPlot[Cases[list, {_, QuantityMagnitude[x_] > 0}]]

How can I structure the pattern for cases to obtain the desired result to include only non-zero values of the magnitude?


Viewing all articles
Browse latest Browse all 41