Search code examples
matlab2dspacecoordinate

Using Coordinate System in Matlab


I've been working on a project involving inverse source problem known within the electromagnetic wave field. The problem i have is that ; I have to define 3 points in a 2D space. These points should have a x,y coordinate of course and a value which will define its' current. Like this:

A1(2,3)=1
A2(2,-2)=2
and so on.

Also i have to define a circle around this and divide it into 200 points. Like the first point would be ; say R=2 ; B1(2,0) ;B50(0,2);B100(-2,0) and so on.

Now i really am having a hard time to define a space in MATLAB and circle it. So what i am asking is to help me define a 2D space and do it as the way i described. Thanks for any help guys!


Solution

  • This kind of code may be use. Look at grid in the Variable editor.

    grid = zeros(50, 50);
    R = 10;
    angles = (1:200)/2/pi;
    x = cos(angles)*R;
    y = sin(angles)*R;
    
    center = [25 20];
    
    for n=1:length(angles)   
        grid(center(1)+1+round(x(n)), center(2)+1+round(y(n))) = 1;
    end
    

    You have to define a grid large enough for your need.