I found this bellow code in internet. While I run the code I noticed following errors.

조회 수: 4 (최근 30일)
clc
clear all;
close all;
filename = 'Registration_Details.xls';
[num,txt] = xlsread(filename);
len=length(txt);
blankimage = imread('certificate_Blank.tiff');
for i=1:len
for j= 2:2
text_names(i,j)=txt(i,j);
end
end
% Obtain names from the txt variable which are in 2nd column
for i=1:len
for j= 3:3
text_topic(i,j)=txt(i,j);
end
end
for i=2:len
text_all=[text_names(i,2) text_topic(i,3)];
position = [100 258;120 416];
RGB = insertText(blankimage,position,text_all,'FontSize',22,'BoxOpacity',0);
figure
imshow(RGB)
y=i-1;
filename=['Certificate_Topic_' num2str(y)];
lastf=[filename '.png'];
saveas(gcf,lastf)
end
Errors:
Error using matlab.graphics.internal.name (line 101)
Cannot create output file '.\Certificate_Topic_1.png'.
Error in print (line 71)
pj = matlab.graphics.internal.name( pj );
Error in saveas (line 181)
print( h, name, ['-d' dev{i}] )
Error in MainCode (line 36)
saveas(gcf,lastf)

답변 (1개)

Jan
Jan 2019년 11월 21일
This is a strange and inefficient code. Replace e.g.
for i=1:len
for j= 2:2
text_names(i,j)=txt(i,j);
end
end
to
text_names(:, 2) = txt(:, 2);
The actual error message can be caused by a write-protected folder. The solution is to write the output to a folder, in which you have write-permissions.

카테고리

Help CenterFile Exchange에서 Scope Variables and Generate Names에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by