필터 지우기
필터 지우기

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
Sujay Muniraju
Sujay Muniraju 2023년 8월 30일
편집: Sujay Muniraju 2023년 9월 1일
i understand we can export via exportgraphics pdf also thanks.

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

채택된 답변

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