hi guys, i need some expert advice on this.
I have successfully created the tcp connection between processing and matlab. I am using oscp5 library for that. I am sending an array containing x and y coordinates from processing and my intent is to draw a sine wave in matlab with these received x & y values.
My question is how i can separate the coordinates after receiving in matlab? Also, i think i need to alter some setting in tcpip object because i am not receiving the same values in matlab, which i am sending.
You can see the code and their values below.
-------------Processing Code-------------
import oscP5.*;
import netP5.*;
OscMessage myMessage;
OscP5 oscP5tcpClient;
int xspacing = 16; // How far apart should each horizontal location be spaced
int w; // Width of entire wave
float theta = 0.0; // Start angle at 0
float amplitude = 75.0; // Height of wave
float period = 500.0; // How many pixels before the wave repeats
float dx; // Value for incrementing X, a function of period and xspacing
float[] yvalues; // Using an array to store height values for the wave
int x;
void setup() {
size(640, 360);
oscP5tcpClient = new OscP5( this, "141.44.219.161", 1234, OscP5.TCP);
w = width+16;
dx = (TWO_PI / period) * xspacing;
yvalues = new float[w/xspacing];
}
void draw() {
background(0);
calcWave();
OscMessage myMessage = new OscMessage("/test");
myMessage.add(new float[] { x*xspacing, height/2+yvalues[x]}); =====>>> These values are sent to Matlab.
oscP5tcpClient.send(myMessage);
print(x*xspacing, height/2+yvalues[x]);
}
void calcWave() {
// Increment theta (try different values for 'angular velocity' here
theta += 0.02;
// For every x value, calculate a y value with sine function
float x = theta;
for (int i = 0; i < yvalues.length; i++) {
yvalues[i] = sin(x)*amplitude;
x+=dx;
}
}
void renderWave() {
noStroke();
fill(255);
// A simple way to draw the wave with an ellipse at each location
for (int x = 0; x < yvalues.length; x++) {
ellipse(x*xspacing, height/2+yvalues[x], 16, 16);
}
}
--------------------------MATLAB Code----------------------------
>> tcpipServer = tcpip('141.44.219.161',1234,'NetworkRole','Server');
>> fopen(tcpipServer)
>> data =fread(tcpipServer)
data =
0
0
0
20
47
116
101
115
116
0
0 ===>>> these are values i am receving in matlab, which is completely different from what i am sending.
0
44
102
102
0
0
0
0
0
67
53
127
249
>>
------------------------------------------------------------------
Values which i am sending from processing is look something like below