3
$\begingroup$

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.

$\endgroup$
5
$\begingroup$
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}} *)
$\endgroup$
  • $\begingroup$ Both of these work perfectly. Thank you!! $\endgroup$ – Amara Sep 17 '14 at 16:09
  • $\begingroup$ @Amara, my pleasure. Thank you for the accept. And welcome to MMA.SE. $\endgroup$ – kglr Sep 17 '14 at 16:24
4
$\begingroup$

You can also use Dot:

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

(*  {{560., 0.041}, {561., 0.0495}, {7990., 0.00435}, {8000., 0.00434}}  *)
$\endgroup$
  • $\begingroup$ 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. $\endgroup$ – Mr.Wizard Sep 17 '14 at 20:17
1
$\begingroup$

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

See also: Elegant operations on matrix rows and columns

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.