1
$\begingroup$

I have managed to import my data into mathematica, but I can't find a way to show the plot the way it was in the lab (Matlab automatically generated file usually show me a graph). Is there a way Mathematica can tell what is in the file and show the graph the way it was in Matlab. Every command (for Matlab) is in the file already.

%********************************************
clear
M=[
% Frequence       Amplitude       Phase
10      9.359000E+0     1.340000E+0;
11      9.341000E+0     320.000000E-3;
13      9.418000E+0     10.000000E-3;
14      9.405000E+0     -90.000000E-3;
16      9.410000E+0     -70.000000E-3;
18      9.408000E+0     -60.000000E-3;
20      9.407000E+0     -60.000000E-3;
22      9.407000E+0     -60.000000E-3;
25      9.407000E+0     -60.000000E-3;
28      9.405000E+0     -50.000000E-3;
32      9.406000E+0     -60.000000E-3;
35      9.407000E+0     -50.000000E-3;
40      9.405000E+0     -50.000000E-3;
45      9.405000E+0     -50.000000E-3;
50      9.406000E+0     -40.000000E-3;



];
figure (1);
semilogx(M(:,1),M(:,2));
grid;
title('Amplitude et Phase');
xlabel('Frequence en Hz');
ylabel('Amplitude en dB');

of course i skimmed the data but this is my Matlab code.

% second plot
figure (2);

title('Amplitude et Phase');
semilogx(M(:,1),M(:,3));
grid;
xlabel('Frequence en Hz');
ylabel('Phase en degre');
$\endgroup$
  • $\begingroup$ The commands and syntax in Mathematica are different from those found in Matlab, so your code will not work as you have presented it. See the documentation for ListLogLinearPlot, which is Mathematica's version of semilogx for sampled data. See also List if you're unfamiliar with how to format your data for use in ListLogLinearPlot. $\endgroup$ – IPoiler Jan 21 '16 at 22:24
5
$\begingroup$

I don't see why one would expect that two so dissimilar program languages with a completely different syntax and philosophy like MatLAB and Mathematica could use each others programs.

To get your plot you really have to code in Mathematica (or Wolfram Language, as we're supposed to call it nowadays):

First, I copy the data as a string and let it interpret as a table, after removing the semicolons at the end of the lines:

m =
 ImportString[
  StringReplace["10      9.359000E+0     1.340000E+0;
   11      9.341000E+0     320.000000E-3;
   13      9.418000E+0     10.000000E-3;
   14      9.405000E+0     -90.000000E-3;
   16      9.410000E+0     -70.000000E-3;
   18      9.408000E+0     -60.000000E-3;
   20      9.407000E+0     -60.000000E-3;
   22      9.407000E+0     -60.000000E-3;
   25      9.407000E+0     -60.000000E-3;
   28      9.405000E+0     -50.000000E-3;
   32      9.406000E+0     -60.000000E-3;
   35      9.407000E+0     -50.000000E-3;
   40      9.405000E+0     -50.000000E-3;
   45      9.405000E+0     -50.000000E-3;
   50      9.406000E+0     -40.000000E-3;", ";" -> ""], "Table"]

Then the plot itself:

ListLogLinearPlot[m[[All, {1, 2}]],
 Frame -> True,
 GridLines -> Automatic,
 FrameLabel -> {"Frequence en Hz", "Amplitude en dB", "", ""},
 PlotLabel -> "Amplitude et Phase",
 PlotRange->All
]

Mathematica graphics

The second plot, with a few options added to draw connecting lines:

ListLogLinearPlot[m[[All, {1, 3}]],
 Frame -> True,
 GridLines -> Automatic,
 FrameLabel -> {"Frequence en Hz", "Phase en degre", "", ""},
 PlotLabel -> "Amplitude et Phase",
 PlotRange -> All,
 Joined -> True,
 PlotMarkers -> Automatic
 ]

Mathematica graphics

$\endgroup$
6
$\begingroup$

Another way is to use the MATLink package (see Calling MATLAB from Mathematica), if you have Matlab installed.

(* See http://matlink.org for installation *)
Needs["MATLink`"];
OpenMATLAB[]

test = MScript["test",
  "
  %********************************************
  clear
  M=[
  % Frequence       Amplitude       Phase
  10      9.359000E+0     1.340000E+0;
  11      9.341000E+0     320.000000E-3;
  13      9.418000E+0     10.000000E-3;
  14      9.405000E+0     -90.000000E-3;
  16      9.410000E+0     -70.000000E-3;
  18      9.408000E+0     -60.000000E-3;
  20      9.407000E+0     -60.000000E-3;
  22      9.407000E+0     -60.000000E-3;
  25      9.407000E+0     -60.000000E-3;
  28      9.405000E+0     -50.000000E-3;
  32      9.406000E+0     -60.000000E-3;
  35      9.407000E+0     -50.000000E-3;
  40      9.405000E+0     -50.000000E-3;
  45      9.405000E+0     -50.000000E-3;
  50      9.406000E+0     -40.000000E-3;



  ];",
  "Overwrite" -> True]

MScript["test"]

MEvaluate@test

m = MGet["M"]  (* this retrieves the matrix M *)
(*
  {{10., 9.359, 1.34}, {11., 9.341, 0.32}, {13., 9.418, 0.01}, {14., 
    9.405, -0.09}, {16., 9.41, -0.07}, {18., 9.408, -0.06}, {20., 
    9.407, -0.06}, {22., 9.407, -0.06}, {25., 9.407, -0.06}, {28., 
    9.405, -0.05}, {32., 9.406, -0.06}, {35., 9.407, -0.05}, {40., 
    9.405, -0.05}, {45., 9.405, -0.05}, {50., 9.406, -0.04}}
*)

ListLogLinearPlot[m[[All, 1 ;; 2]], Joined -> True, PlotRange -> All,
 PlotLabel -> "Amplitude et Phase",
 Frame -> True, GridLines -> All,
 FrameLabel -> {"Frequence en Hz", "Amplitude en dB"}]

Mathematica graphics

Similarly for the other plot:

ListLogLinearPlot[m[[All, {1, 3}]],...]
$\endgroup$

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.