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