How can I modify the following code to send data row by row instead of column by column using UDP?

I have data with five columns. Currently, I am sending each column one at a time. For example, I send column 1 first, followed by column 2, and so on. However, I want to modify the code to send each row at a time instead of each column.
clear;clc
client_port = 10011;
client_address = '192.168.100.201';
to = [data(:,1).' ;data(:,2).' ;data(:,3).' ;data(:,4).';data(:,5).'];
u1 = udpport("IPV4","OutputDatagramSize",6610);
for j = 1:5
write(u1,(to(j,1:length(toa_arr))),"double",client_address,client_port);
end

Réponses (1)

"I have data with five columns"
I assume that's the variable data in your code.
You can write data by row the exact way you are currently writing to by row:
for j = 1:length(toa_arr)
write(u1,data(j,:),"double",client_address,client_port);
end
Or by reshaping data (or the part of data you want to write - the relation between length(toa_arr) and the size of data is not clear) to be a vector of elements in the correct order:
write(u1,reshape(data(1:length(toa_arr),:).',[],1),"double",client_address,client_port);
By the way, I notice that the variable pdw in the mat file you uploaded is of size 6610-by-5. I guess this is your data with five columns. Note that "OutputDatagramSize" is in bytes, and a double is 8 bytes, so you may have wanted to specify OutputDatagramSize as 6610*8 instead of 6610.

7 commentaires

@Voss Thank you for your comment. If I don't know the size of the data, as in the example where I have a dataset of size 6610x5, and I am receiving real-time data with 5 columns but an unknown number of rows, how can I modify the code to handle this?
@Voss How can i read this on Client reciving side?
@Voss It takes so much time in sending value. How can i modified that?
"I am receiving real-time data with 5 columns but an unknown number of rows"
for j = 1:size(data,1)
write(u1,data(j,:),"double",client_address,client_port);
end
"How can i read this on Client reciving side?"
"It takes so much time in sending value. How can i modified that?"
I have no idea.
@Voss Thanks for your reply. Can you please modified the code on reciever side in which wait for 1 second to read all data.
To wait for 1 second, you can use
t = tic;
while toc(t) < 1
% do nothing, just wait
end
@Voss But When i am reading the data data = read(u2,6610,"double"); in this command i need to write the value like 6610. How can i modified this? Can you please check the this question i have posted recently.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Get Started with MATLAB dans Centre d'aide et File Exchange

Produits

Version

R2022b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by