Matlab Report Generator (Unknown Error to me)

8 vues (au cours des 30 derniers jours)
Angus Wong
Angus Wong le 13 Juil 2020
Commenté : Angus Wong le 13 Juil 2020
Hi,
This is a section of my code in which Matlab 100% throws an error that I don;t know why and how. Can anyone give me some suggestions?
beamprop([0 0;0.406 0;0.406 0.203;0.403 0.203;0.403 0.003;0.003 0.003;0.003 0.203;0 0.203],[],[]);
function [final,coor]=beamprop(coor,knowndim,points)
arguments
coor(:,2,1)sym
knowndim(:,5,1)sym % [area xbar ybar Ix Iy]
points(:,2,1)sym
end
final=sym(zeros(6,1)); % [area xbar ybar Ix Iy Ixy]
if size(coor,1)~=0
try
double(coor);
catch
syms x;
end
prop=sym(zeros((size(knowndim,1)+1),5));
if size(knowndim,1)~=0
prop(2:end,:)=knowndim;
end
A=sym(zeros(size(coor,1),1));
Q=[A A]; % 1st moment of area
I=[A A A]; % 2nd moment of area
figure;
hold on;
for ct=1:(size(coor,1)-1)
A(ct)=coor(ct,1)*coor((ct+1),2)-coor(ct,2)*coor((ct+1),1);
t=coor(ct,1)*coor((ct+1),2)-coor((ct+1),1)*coor(ct,2);
Q(ct,1)=(coor(ct,1)+coor((ct+1),1))*t;
Q(ct,2)=(coor(ct,2)+coor((ct+1),2))*t;
plot([coor(ct,1);coor((ct+1),1)],[coor(ct,2);coor((ct+1),2)],'k');
end
A(end)=coor(end,1)*coor(1,2)-coor(end,2)*coor(1,1);
t=coor(end,1)*coor(1,2)-coor(1,1)*coor(end,2);
Q(end,1)=(coor(end,1)+coor(1,1))*t;
Q(end,2)=(coor(end,2)+coor(1,2))*t;
plot([coor(end,1);coor(1,1)],[coor(end,2);coor(1,2)],'k');
grid minor;
hold off;
if sign(sum(A))==-1
Q=-Q;
A=-A;
end
prop(1,1)=simplify(sum(A)/2);
Qx=sum(Q(:,1))/6;
prop(1,2)=simplify(Qx/prop(1,1));
Qy=sum(Q(:,2))/6;
prop(1,3)=simplify(Qy/prop(1,1));
prop(1,4)=sum(I(:,1))/12-prop(1,1)*prop(1,3)^2;
prop(1,5)=sum(I(:,2))/12-prop(1,1)*prop(1,2)^2;
final(1)=simplify(sum(prop(:,1)));
final(2)=simplify(sum(prop(:,1).*prop(:,2))/final(1));
final(3)=simplify(sum(prop(:,1).*prop(:,3))/final(1));
coor(:,1)=coor(:,1)-final(2);
coor(:,2)=coor(:,2)-final(3);
for ct=1:(size(coor)-1)
t=coor(ct,1)*coor((ct+1),2)-coor((ct+1),1)*coor(ct,2);
I(ct,1)=t*(coor(ct,2)^2+coor(ct,2)*coor((ct+1),2)+coor((ct+1),2)^2);
I(ct,2)=t*(coor(ct,1)^2+coor(ct,1)*coor((ct+1),1)+coor((ct+1),1)^2);
I(ct,3)=t*(coor(ct,1)*coor((ct+1),2)+coor((ct+1),1)*coor(ct,2)+2*coor(ct,1)*coor(ct,2)+2*coor((ct+1),1)*coor((ct+1),2));
end
t=coor(end,1)*coor(1,2)-coor(1,1)*coor(end,2);
I(end,1)=t*(coor(end,2)^2+coor(end,2)*coor(1,2)+coor(1,2)^2);
I(end,2)=t*(coor(end,1)^2+coor(end,1)*coor(1,1)+coor(1,1)^2);
I(end,3)=t*(coor(end,1)*coor(1,2)+coor(1,1)*coor(end,2)+2*coor(end,1)*coor(end,2)+2*coor(1,1)*coor(1,2));
final(4)=simplify(sum(I(:,1))/12);
final(5)=simplify(sum(I(:,2))/12);
final(6)=simplify(sum(I(:,3))/24);
points(:,1)=points(:,1)-final(2);
points(:,2)=points(:,2)-final(3);
coor=[coor;points];
elseif size(coor,1)==0 && size(knowndim,1)~=0 && size(points,1)~=0
final(1)=sum(knowndim(:,1));
final(2)=sum(knowndim(:,1).*knowndim(:,2))/final(1);
final(3)=sum(knowndim(:,1).*knowndim(:,3))/final(1);
final(4)=sum(knowndim(:,4)+knowndim(:,1).*(knowndim(:,3)-final(3)).^2);
final(5)=sum(knowndim(:,5)+knowndim(:,1).*(knowndim(:,2)-final(2)).^2);
final(6)=sum(knowndim(:,1).*(knowndim(:,2)-final(2)).*(knowndim(:,3)-final(3)));
points(:,1)=points(:,1)-final(2);
points(:,2)=points(:,2)-final(3);
coor=points;
else
error('Error! No inputs detected!');
end
import mlreportgen.report.*
import mlreportgen.dom.*
rpt = Report('Cross Section','pdf');
tp=TitlePage;
tp.Title='Cross Sectional Properties';
tp.Subtitle='Area, Centroids and Second Moments of Area';
tp.Author = 'Angus';
add(rpt,tp);
ch1=Chapter;
ch1.Title='Cross Section';
sec1=Section;
sec1.Title='Graph of Cross Section';
add(sec1,Figure);
add(ch1,sec1);
close gcf;
sec2=Section;
sec2.Title = 'Numeric Properties of the Cross Section';
para=Paragraph(sprintf('Area = %g',final(1)));
add(sec2,para);
add(ch1,sec2);
add(rpt,ch1); % error occured here.
close(rpt);
rptview(rpt);
end
Error thrown in the Command Window:
Error using mlreportgen.report.Figure/createSnapshotFigure
Figure is invalid. Please use valid path of the figure file or valid figure handle
Error in mlreportgen.report.Figure/getSnapshotImageImpl
Error in mlreportgen.report.Figure/getContent
Error in mlreportgen.report.ReportForm/fillHole
Error in mlreportgen.report.ReporterBase/processHole
Error in mlreportgen.report.ReportForm/fillForm
Error in mlreportgen.report.ReporterBase/getDocumentPart
Error in mlreportgen.report.ReporterBase/getImpl
Error in mlreportgen.report.internal.LockedForm.add
Error in mlreportgen.report.internal.LockedForm.add
Error in mlreportgen.report.ReportForm/fillHole
Error in mlreportgen.report.Section/processHole
Error in mlreportgen.report.ReportForm/fillForm
Error in mlreportgen.report.ReporterBase/getDocumentPart
Error in mlreportgen.report.ReporterBase/getImpl
Error in mlreportgen.report.Section/getImpl
Error in mlreportgen.report.internal.LockedForm.add
Error in mlreportgen.report.internal.LockedForm.add
Error in mlreportgen.report.ReportForm/fillHole
Error in mlreportgen.report.Section/processHole
Error in mlreportgen.report.Chapter/processHole
Error in mlreportgen.report.ReportForm/fillForm
Error in mlreportgen.report.ReporterBase/getDocumentPart
Error in mlreportgen.report.ReporterBase/getImpl
Error in mlreportgen.report.Section/getImpl
Error in mlreportgen.report.internal.LockedForm.add
Error in mlreportgen.report.ReportBase/add
Error in beamprop (line 103)
add(rpt,ch1);
Many thanks!

Réponse acceptée

Walter Roberson
Walter Roberson le 13 Juil 2020
figure;
%....
close gcf;
Do not do things that way. Instead record the figure() handle, and close() the handle.
  1 commentaire
Angus Wong
Angus Wong le 13 Juil 2020
Thank you so much, my code now works!

Connectez-vous pour commenter.

Plus de réponses (0)

Produits


Version

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by