How to send Table using UDP in MATLAB

Hello, I hope you are doing well. I want to send Table using UDP. How can i do that?
I have write the following code but it does not working. Can anyone help me with that
client_port = 10011;
clientAddress = '192.168.100.202';
% Define the table
C = {5 "cereal" 110 "C+"; 12 "pizza" 140 "B";...
23 "salmon" 367 "A"; 2 "cookies" 160 "D"};
T = cell2table(C, 'VariableNames', {'Age', 'FavoriteFood', 'Calories', 'NutritionGrade'});
% Open a UDP port
u2 = udpport("IPV4",'LocalPort',client_port);
% Send the data
write(u2, clientAddress, client_port, T);

댓글 수: 1

Image Analyst
Image Analyst 2024년 3월 4일
Save yourself some work and add only tags that are actually related to your question, not 22 unrelated (like image processing) or useless tags such as matlab, matlab code, code, etc.

댓글을 달려면 로그인하십시오.

답변 (1개)

Voss
Voss 2024년 3월 3일

0 개 추천

According to the documentation, the "data" input is:
"Vector of values to write, specified as a row (1-by-N) or column (N-by-1) array of numeric data, string, or character vector."
A table is none of those things.
Also, the order of the inputs is:
"write(u,data,destinationAddress,destinationPort)"
or
"write(u,data,datatype,destinationAddress,destinationPort)"

댓글 수: 7

Med Future
Med Future 2024년 3월 3일
@Voss How can i write Table using UDP? Can you help me with that to modified the above code?
Voss
Voss 2024년 3월 3일
If the table contains numeric data, strings, and/or character vectors only, then you can write its contents in multiple write calls, where each call writes data only of one class, e.g., by writing one column of the table at a time.
@Voss I understand. Can you please help me in modifiying the code Like i have the cell array. which includes numeric values and strings. I want to write it. How can i modified the write function?
% Define the table
C = {5 "cereal" 110 "C+"; 12 "pizza" 140 "B";...
23 "salmon" 367 "A"; 2 "cookies" 160 "D"};
for ii = 1:numel(C)
write(u2, C{ii}, class(C{ii}), clientAddress, client_port);
end
Med Future
Med Future 2024년 3월 3일
@Voss Thanks. I will check it and let you know. if the problem still exist
Med Future
Med Future 2024년 3월 4일
@Voss how Can i read this table on recieving side?

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Introduction to Installation and Licensing에 대해 자세히 알아보기

질문:

2024년 3월 3일

댓글:

2024년 3월 4일

Community Treasure Hunt

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

Start Hunting!

Translated by