loop of exportgraphics fails for dot indexing only in the second loop

조회 수: 5 (최근 30일)
Hello guys, how are you?
I got a piece of my code which meant to show and export a histogeram automatutically. it works somewhy for the first indice, but then it fails. i saw several posts about this problem, which talked about handle (which I don't use anyways) and critical failure of indexing (which I belive it is not in my case).
the code:
for n=1:length(allcellsnames)
subplot(1,3,n)
histogram(allcellsareastot{1,n});
myAxes=findobj(finalhis,'Type','Axes');
fnfh=append(append(erase(lastentryname, '.csv'),' finalhis'));
fhpath=(append(pwd ,append('\',append('summary figure', append('\',append('summary figure ', append(num2str(minint(n)), append(' i ', append(num2str(maxint(n)), '.png')))))))))
exportgraphics(myAxes,(fhpath));
analysisdata{9+n,1}=allcellsnames{n};
analysisdata{9+n,2}=allcellsareastot{1,n};
end
The first indice goes good and it saves my image. in the second it subplots it to the figure, but somewhy fails to save.
it fails in the " exportgraphics(myAxes,(fhpath));"
here is the output that shows the first is fine, but the second messed up:
fhpath =
'C:\Users\Ifrac\Desktop\מעבדה\matlab\Voronoi analysis\voronoi code test\summary figure\summary figure 0.5 i 40.png'
fhpath =
'C:\Users\Ifrac\Desktop\מעבדה\matlab\Voronoi analysis\voronoi code test\summary figure\summary figure 1 i 45.png'
Error using exportgraphics
Dot indexing is not supported for variables of this type.
Error in Voronoi_exclude_borders_21122022allclareamatrixndfx (line 378)
exportgraphics(myAxes,(fhpath));
I would really appriciate any help :)
Thanks,
Amit.
  댓글 수: 2
Stephen23
Stephen23 2022년 12월 23일
What is FINALHIS ?
Note that you do not need to call APPEND() multple times in one line like that: APPEND() accepts multiple inputs, so you only need to call it once. Even better would be to replace it with FULLFILE() and SPRINTF().
Amit Ifrach
Amit Ifrach 2022년 12월 23일
Hi sephen, thanks!
finalhis is the figure:
finalhis=figure(ADcntr);
and thanks for the append tip! :)
Amit.

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

채택된 답변

Sulaymon Eshkabilov
Sulaymon Eshkabilov 2022년 12월 24일
As you stated: finalhis=figure(ADcntr);
Then this command: exportgraphics(myAxes,(fhpath));
has to be:
exportgraphics(finlhis,fhpath);
  댓글 수: 3
Sulaymon Eshkabilov
Sulaymon Eshkabilov 2022년 12월 25일
Welcome. It requires a figure handle and thus, you'd need such syntax.
Walter Roberson
Walter Roberson 2022년 12월 25일
exportgraphics(OBJ, FILESPEC) saves the specified graphics to a file.
OBJ is the handle of any type of an axes, a figure, a chart that can
be a child of the figure, a tiled chart layout, or a container within
the figure.

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

추가 답변 (1개)

Walter Roberson
Walter Roberson 2022년 12월 24일
try
myAxes = subplot(1,3,n);
histogram(myAxes, allcellsareastot{1,n});
with no find()
  댓글 수: 3
Walter Roberson
Walter Roberson 2022년 12월 25일
I do not know where you got the idea that allcellsareastot was to be passed to exportgraphics.
for n=1:length(allcellsnames)
myAxes = subplot(1,3,n);
histogram(myAxes, allcellsareastot{1,n});
fnfh=append(append(erase(lastentryname, '.csv'),' finalhis'));
fhpath=(append(pwd ,append('\',append('summary figure', append('\',append('summary figure ', append(num2str(minint(n)), append(' i ', append(num2str(maxint(n)), '.png')))))))))
exportgraphics(myAxes,(fhpath));
analysisdata{9+n,1}=allcellsnames{n};
analysisdata{9+n,2}=allcellsareastot{1,n};
end
Walter Roberson
Walter Roberson 2022년 12월 25일
By the way, we recommend that you use fullfile() instead of building file names with '/' or '\' yourself.

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

카테고리

Help CenterFile Exchange에서 Title에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by