How to store real-time data in a file that can be accessed in matlab elsewhere?

18 views (last 30 days)
I am working on a program to extract data from image using OCR and store in variables. The process is that the image will be refreshed with a different value after a regular interval (at least 10 seconds). So, I want to run loop with the following process which extracts the numerical from the image and also stores the time of the process, as demonstrated below
%% this complete demonstration will be put into a for loop for obtaining data from similar images
image = importdata('out.png');
image = imresize(image,4);
image = uint8(255*imbinarize(rgb2gray(image)));
%imshow(image)
ocrResults = ocr(image, TextLayout="word");
Iocr = insertObjectAnnotation(image,'rectangle',ocrResults.WordBoundingBoxes,ocrResults.WordConfidences);
imshow(Iocr);
Once OCR gets the value, I store the value and the time (at the instance of OCR processing) into the table.
datavalue = str2num(ocrResults.Text);
time = datetime('now','TimeZone','Asia/Seoul','Format','yyyy-MM-dd HH:mm:ss.SSS');
time = cellstr([string(time)]); % for storing time for exporting
disp([datavalue time]) % this is just for demonstrating the output
{[260.4900]} {'2023-01-05 11:43:41.464'}
Currently, I used the following code to store in the excel file (it takes a second to store). Since the above-mentioned process will be put in a for-loop, so I am just writing the storing code.
xlswrite('name.xls', ftime, sheetNumber, ['A' num2str(i)]);
xlswrite('name.xls', data, sheetNumber, ['B' num2str(i)]);
I have very basic knowledge of Matlab, and I want to efficiently store these data into some sort of file (or files) in a LAN shared folder from 4 computers and then access the data in another computer for processing in realtime (the data keeps on updating).

Accepted Answer

Avinash
Avinash on 10 Jan 2023
Hi Usman
  • By keeping the MATLAB current working directory in the same place as the target folder, you can first create a new text file using the fopen function in the target folder location that is accessible from other machines as well.
  • Additionally, you can override the contents of an existing file by using the fopen and fprintf function.
  • To write into a text file, keep the property set to "wt".
  • Then, use the writetable function to write your data in table format.
To learn more about the fopen, fprint and writetable functions, refer the documentation links mentioned below:
Thanks
Avinash

More Answers (0)

Categories

Find more on Data Import and Export in Help Center and File Exchange

Products


Release

R2022b

Community Treasure Hunt

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

Start Hunting!