From: Jim on
I've looked at a few other threads where people are asking about ternary-like functionality, and most of the solutions are of the "punt" variety. (i.e. they seem to approach the larger issue and rework other parts of the solution, rather than provide something similar in-place) I have a problem that I haven't been able to solve without a ternary-like feature in place.

I have a matrix with three columns. The first is the X-axis, the second is the Y-axis and the third is an indicator that I need to use to determine what kind of point to draw. Basically, an 'x' if the value in the third column is positive and a 'o' if the value in the third column is negative. An additional wrinkle is that I need to draw nothing if the third column is zero.

In my C-like thinking, I would use a ternary operator to determine what formatting string gets sent to the plot function. Of course, the hacker in me would probably "plot" the null values too, with the color set to the same as the background, just to be pedantic, and provide the opportunity to add them later if need be.

Anyway, I'm trying to find some way to do this within the context of a plot call, and avoid creating a separate function to return the correct formatting string, and looping thru calling that each time on successive calls to plot.


[ In my real ideal world, plot would actually have something like this. But, perhaps that's a Lisp programmer talking and not a C one. :-) ]


Thanks!
Jim
From: Jan Simon on
Dear Jim!

> I have a matrix with three columns. The first is the X-axis, the second is the Y-axis and the third is an indicator that I need to use to determine what kind of point to draw. Basically, an 'x' if the value in the third column is positive and a 'o' if the value in the third column is negative. An additional wrinkle is that I need to draw nothing if the third column is zero.

You have some input and want some output. I do not think, that this is a question of C-style or Lisp-style. Any operator, which creates the wanted output, is working well...

I do not understand your input: You have a [N x 3] matrix and the elements in the 3rd columns are either 'x', 'o' or 0 ?! Then the matrix must be a CHAR array. Where are your data for plotting?

Instead of plotting data with the background color, better set the position to Inf. In both cases the point is invisible, but with Inf this does not depent on the display properties, e.g. if you export the figure as EPS file.

Kind regards, Jan