Clear Filters
Clear Filters

how to create a table with different datatypes [ex: char, string ,numbers ,image ] in a same column?

1 view (last 30 days)

I need to create auto generated report, which includes text, numbers , and images in a coloum of the table. and then save it as pdf,
column1:
Contents=["User Name","System Name","Date and Time","Plot"]; -(all string)
column 2:
Details=[userName,systemName,dnT, Image]
userName,systemName,dnT belongs to char/string
Image- belongs to image (jpg/png)

  6 Comments

Sign in to comment.

Accepted Answer

Riya
Riya on 30 Aug 2023
Hello Sujay Muniraju
As per my understanding, you want to create a table with different data types in a single column.
In this case, as a workaround, you can use the "table" data structure in MATLAB.
Please refer the below sample code in this regard:
% Create the data for the table
Contents = ["User Name", "System Name", "Date and Time", "Plot"]
userName = 'ABCD'
systemName = 'My System'
dnT = '2021-09-30 10:30:00'
imagePath = 'C:\path\image.jpg'
% Load the image
imageData = imread(imagePath)
% Create the table
T = table(Contents', {userName; systemName; dnT; imageData}, 'VariableNames', {'Column1', 'Column2'})
% Display the table
disp(T)
In the above code, the Contents variable contains the string values for the first column, and the variables userName, systemName, dnT, and imageData hold the corresponding values for the second column.
Further, to save the table as a PDF, you can use the exportgraphics function in MATLAB. Here's an example onhow you can save the table as a PDF:
% Save the table as a CSV file
writetable(T, 'table.csv');
% Convert the CSV file to PDF using external tools or libraries
% For example, you can use MATLAB's built-in support for calling external commands:
system('libreoffice --convert-to pdf table.csv');
Make sure to replace 'path/to/image.jpg' with the actual path to your image file.
Upon using the "exportgraphics" function with the 'ContentType', 'vector' option, MATLAB will generate a high-quality vector-based PDF file that includes the table and the image.
Besides, please note that if you want to display the image directly in the MATLAB Command Window, you can use the "imshow" function. However, if you want to include the image in the table, you will need to save it separately and provide the path or image data as shown in the sample code above.
For more information regarding the functions used above, you can refer following documents

More Answers (0)

Categories

Find more on Printing and Saving 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!