Sending an image or a text file to another instance of matlab with tcpip connection

Hello,
I'm a beginner in MatLab programmation and I'm trying to send a file to another instance of MatLab using the tcpip client/server .
For this i need to send first the size and the number of bytes of the file in order to reshape it. Unfortunately I don't manage to send the size because it's a vector and I don't know how to do it with this kind of value. For the number of bytes I used fprintf but it seems that i can do the same for the vector.
If anyone can help me it would be great. Thanks !

 Réponse acceptée

fprintf(socket, '%d ', ndim(TheImage));
fprintf(socket, '%d ', size(TheImage));
Sending the number of dimensions first allows you to send variable number of entries for the size(), according to the matrix dimension.
Are you sending the number of bytes in the file, or the number of entries in the array representing the data?
If you are sending text files, are you sending them with carriage returns or without? Does control-Z (26) represent end-of-file or is it just another data byte?
How are you indicating that you are sending text (for which newline is end of line) or image (for which newline is just a data byte) ?
Are you sending text files in UTF-8 encoding?

1 commentaire

but did you know how to send a image or something else via GUI matlab? i want to send a image between 2 matlab in 2 PCs

Connectez-vous pour commenter.

Plus de réponses (3)

My program is based on this:
So I send the number of bytes the function "whos" return me, same for the sizes.
For the text files I will send them without carriage return and in UTF-8 encoding but for the moment I have just tried to send image, I will see this after.
I tried fprintf(socket, '%d ', ndim(TheImage)); But it didn't work, it say : Undefined function or method 'ndim' for input arguments of type 'uint8'.
Maybe I don't use the good function to open the picture. I use importdata('image.jpg').

3 commentaires

Sorry, I keep getting confused whether the name is ndim() or ndims(); you should use ndims()
I have succeed to send my image, thanks a lot !
Hello, I would like to do the same but I can't make it work, could you help me ?

Connectez-vous pour commenter.

I have an other question : is it possible to make a connection between matlab and a PIC using USB port in order to send data to the PIC? Or I need to use a usb to serial converter ?

7 commentaires

You might be able to find a PIC board that had a built-in USB port, but usually you would need a USB to serial convertor.
And if i use an USB to serial convertor, in order to set up the connection, do I need to use the serial function or the visa one?
If you are communicating with a PIC, chances are that you would be wanting to use serial functions rather than visa. I could possibly be more specific if you were to refer to a particular PIC development board.
We are using a pic 32mx220f032b but I can't refer you a specific PIC development board because it's the task of one of my friends to built it. But in our project we need to communicate with USB port.
It appears that that series of devices has built-in USB.
A quick search does not appear to indicate that anyone has developed a VISA interface for it.
So if no VISA interface has been developed it means that i'll only need the SERIAL function ? Thank a lot for your answers, it helps me a lot !

Connectez-vous pour commenter.

@Erwan can u please share me the code ,
to send an image from one system to another.
Thanks

1 commentaire

send the image content or send the image file ? For example if it happens to be jpeg then should the EXIF get transferred as well ? If the input is animated gif then transfer one frame or all of them ?

Connectez-vous pour commenter.

Community Treasure Hunt

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

Start Hunting!

Translated by