0
$\begingroup$

This is a completely simplified example to demonstrate the issue.

I have a matrix, it contains an uninitialized variable. I need to extract that element of the matrix and use in to plot a parametric function of that variable.

m = t; // this is the matrix 1x1, inserted via the graphical context menu;
ParametricPlot[{Part[m, 1], 1}, {t, 0, 1}]

I get an empty plot.


Strangely, it works with the plain plot, I checked it, but I need the parametric one:

Plot[{Part[m, 1]}, {t, 0, 1}]

Could anyone suggest something, please?


I need this to perform certain transformations on "vectors", which contain variables, in order to plot this. I can go without it, currently I'm simply doing:

Print[Part[m, 1]];

then manually copy-pasting the output of Print into ParametricPlot:

ParametricPlot[{t * Cos[Pi], 1}, {t, 0, 1}]

and get what I want. The problem is that I have many more values, than in this example. I thought, that it might be that someone could suggest something.

$\endgroup$
3
  • $\begingroup$ This is not Matlab. As defined, m is a scalar. (And your second example suffers from the same problem btw.) Only m = {{t}} defines a matrix; m = {t} defines a vector. The latter is probably what you are looking for. $\endgroup$ Commented Dec 26, 2019 at 23:59
  • $\begingroup$ @HenrikSchumacher I inserted the matrix via the graphical interface with the context menu's "insert matrix", so it's definitely a matrix. It's just that in my Mathematica notebook it looks like this (without any parenthesis). The second example works, I double checked. $\endgroup$
    – d.k
    Commented Dec 27, 2019 at 0:04
  • 1
    $\begingroup$ Ah, I see. Fortunately, your problem is already solved. $\endgroup$ Commented Dec 27, 2019 at 6:03

1 Answer 1

2
$\begingroup$

When I define m in the manner you describe, I get

m

And, yes, that's definitely a 1 x 1 matrix, which means its first (and only) element is referred by m[[1,1]] (or Part[m,1,1]). So to make a parametric plot, I write

ParametricPlot[{m[[1, 1]], 1}, {t, 0, 1}]

and get

plot

Does this solve your problem?

Note: Anything in Mathematica that qualifies as a matrix will be composed of elements that require two indices to reference them.

$\endgroup$
4
  • $\begingroup$ Thank you, that's exactly what I need. Using m[[1,1]] instead of Part[m, 1] is the solution for some reason $\endgroup$
    – d.k
    Commented Dec 27, 2019 at 0:46
  • $\begingroup$ require two indices to reference them that was the problem. Part works with one index for simple lists, but not matrices $\endgroup$
    – d.k
    Commented Dec 27, 2019 at 0:58
  • $\begingroup$ Or Part[m, 1, 1]. $\endgroup$ Commented Dec 27, 2019 at 1:28
  • $\begingroup$ @RohitNamjoshi. Already said that in the answer $\endgroup$
    – m_goldberg
    Commented Dec 27, 2019 at 1:44

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