Question

I have a matrix

b = [1+ 1i, 2 + 1i, 2+ 2i, 3 + 3i, 3+ 3i ; ...
     1.2 + 2i , 2+2i,  2.1 + 2.1i, 3+2.1i, 3.1 + 3.2i]   

where real(b) is the x coordinate, b(x,:) is one experiment, and imag(b) is the y coordinate.

I want two things:

  1. plot my experiments in a 2d plot as lines (but the points have to be in the right order)

  2. plot my y (usually calledz) coordinate as a surface over the axes x and experiment.

The problem is, that I want lines along the rows and Matlab mixes the coordinates of the complex numbers up and the line appears in a zig-zag all over the place.

The more basic problem is that I want to have bars from x1 to x2 at y1 and I only came up with adding a data point y1 at x1 and x2. But at x2 there is also y2 which seems to confuse Matlab.

Was it helpful?

Solution 2

For question (1), plot(b) is going to give you lines made up of the columns of b. If you switch to using b-transpose, i.e. plot(b'), you'll plot each row separately.

plot(b')
ylim([-4 0])
xlim([-0 4])

Question (2) requires a certain toolbox for the resp function?

OTHER TIPS

You can use Euler's formula to convert your data from Cartesian coordinates to polar coordinates.

clear all; close all;

function [rho, theta] = polarize(z)
  rho = abs(z);
  theta = angle(z);
end

b = [1+ 1i, 2 + 1i, 2+ 2i, 3 + 3i, 3+ 3i;
1.2 + 2i , 2+2i,  2.1 + 2.1i, 3+2.1i, 3.1 + 3.2i];

[rho1, theta1] = polarize(b(1,:));
[rho2, theta2] = polarize(b(2,:));

figure
hold on
polar(theta1, rho1, 'b');
polar(theta2, rho2, 'r');

print('-dpng','euler.png')

Result in Octave: polar plot

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top