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

1 次查看(过去 30 天)

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 个评论

请先登录,再进行评论。

采纳的回答

Riya
Riya 2023-8-30
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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Printing and Saving 的更多信息

产品


版本

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by