# How to multiply specific columns in a matrix of data?

So I need to make a plot of some ~2000 data points I have from a spreadsheet. I'm able to import the data just fine, it stores it like so

sundat


{{280.,0.082},{280.5,0.099},......{3995.,0.0087},{4000.,0.00868}}

And I can call individual data sets or points like so

sundat[[1]]


{280.,0.082}

sundat[[1,1]]


280.

There are 2002 sets of two points of data. Now I can plot it fine using ListPlot, but the raw data I have is in messy units that I want to convert to mks units. I have the conversion factor for each column, but I have no idea how to do this. I presume I need to make a new list to apply this to, but trying something like

data2 = {{sundat[[All,1]]*(conversion1)},{sundat[[All,2]]*(conversion2)}}


just totally messes up the table.

Any help would be appreciated.

• A variety of list manipulation methods can be found here – bobthechemist Sep 17 '14 at 16:04
• Or, to generalize the method given below by Simon Woods (mathematica.stackexchange.com/a/59948/106), sundat.DiagonalMatrix[{2., .5}] – user1066 Jun 9 '17 at 21:42

sundat = {{280., 0.082}, {280.5, 0.099}, {3995., 0.0087}, {4000., 0.00868}};
conversionfactors = {2., .5};

data2 = Transpose[conversionfactors Transpose[sundat]]


or

data2 = conversionfactors # & /@ sundat


both give

(* {{560.,0.041},{561.,0.0495},{7990.,0.00435},{8000.,0.00434}} *)

• Both of these work perfectly. Thank you!! – Amara Sep 17 '14 at 16:09
• @Amara, my pleasure. Thank you for the accept. And welcome to MMA.SE. – kglr Sep 17 '14 at 16:24

You can also use Dot:

sundat.{{2., 0}, {0, .5}}

(*  {{560., 0.041}, {561., 0.0495}, {7990., 0.00435}, {8000., 0.00434}}  *)

• For some reason I always forget this form, though I have been shown it and even used it myself (e.g. (38180)). I don't like the theoretically wasted operations, but it's so well optimized it is still often faster than alternatives. – Mr.Wizard Sep 17 '14 at 20:17

Although I prefer kguler's double Transpose you could also use Inner:

sundat = {{280., 0.082}, {280.5, 0.099}, {3995., 0.0087}, {4000., 0.00868}};

Inner[Times, sundat, {2., .5}, List]

{{560., 0.041}, {561., 0.0495}, {7990., 0.00435}, {8000., 0.00434}}


Or leveraging Simon's solution from: How can I make threading more flexible?

smartThread[sundat {2., .5}]

{{560., 0.041}, {561., 0.0495}, {7990., 0.00435}, {8000., 0.00434}}


A related question: Mapping a function over the parts of a deeply nested Array

• Thanks Mr.Wizard, I always get an upvote or two for that when you use it :-) – Simon Woods Sep 17 '14 at 20:14
• @Simon And well you should! – Mr.Wizard Sep 17 '14 at 20:15