Error while saving image in MATLAB cloud

The error message is the following:
Error using matlab.internal.imagesci.pngwritec
PNG library failed: Write Error.
Error in writepng (line 316)
matlab.internal.imagesci.pngwritec(data, map, filename, colortype, bitdepth, ...
Error in imwrite (line 566)
feval(fmt_s.write, data, map, filename, paramPairs{:});
Error in Videos_guapos_orden_4>generate_image (line 332)
imwrite(imind,map,fulldestination);
Error in Videos_guapos_orden_4 (line 124)
generate_image(x,z,tstep,u2,A,fig,destdirectory);
And the generate_image function is
function generate_image(x,z,tstep,u2,A,fig,destdirectory)
imagen = [flip(u2(3:end-3,:)); u2(3:end-2,:); flip(u2(4:end-3,:)); u2(3:end-2,:); flip(u2(4:end-3,:)); u2(3:end-2,:)];
imagesc(x,z,imagen, [0 A^2]); % draw image and scale colormap to values range
colorbar; % set colorbar
set(gca,'FontSize',20)
Z = length(z)-1;
yticks([0 z(floor(Z/6)) z(floor(Z/3)) z(floor(Z/2)) z(floor(2*Z/3)) z(floor(5*Z/6)) z(Z)])
yticklabels({'-3/2 d','- d','-1/2 d','0','1/2 d','d','3/2 d'})
X = length(x)-1;
xticks([x(1) x(floor(X/4)) x(floor(X/2)) x(floor(3*X/4)) x(X)])
xticklabels({'0','1/4 Z_T','1/2 Z_T','3/4 Z_T','Z_T'})
drawnow
frame = getframe(fig);
im = frame2im(frame);
[imind,map] = rgb2ind(im,256);
thisimage = ['img_',num2str(tstep),'.png'];
fulldestination = fullfile(destdirectory,thisimage);
imwrite(imind,map,fulldestination); % The error occurs HERE
end
The weird thing is that I only get the error in the cloud version of MATLAB. If I run the same code in my desktop, everything goes smoothly.
Anyone has any idea about where I'm messing up the code?
Thanks!

4 commentaires

What is the value of destdirectory?
Side question: why do you both to convert to indexed image form and write out the indexed form (with colormap). Is there a reason why you are not just writing out the rgb directly? Is this a context that needs the image quantized to 256 colors specifically?
Gabriel
Gabriel le 6 Mai 2023
Yeah... So I had messed up the value of destdirectory... It had many more '/' than needed and I created the following:
I don't know why it solved the issue. Thank you!
Side question: Bassically, I made that bit of the code a long time ago, when I had never used MATLAB before. I guess I googled how to save a plot to jpg in MATLAB and copied what I've found. As it worked, I've never changed. But yeah, I just realised it was pretty much unnecesary work.
Thank you for the response Walter!
It would have been better to not have the \ as part of the folder name. That is permitted on Unix but causes interoperability problems.
Gabriel
Gabriel le 6 Mai 2023
Yeah... It was a badly crafted directory.

Connectez-vous pour commenter.

 Réponse acceptée

Gabriel
Gabriel le 6 Mai 2023

0 votes

I messed up the value of destdirectory by entering too many '/'. Fixing it solved the problem.

Plus de réponses (0)

Catégories

En savoir plus sur MathWorks Cloud Center dans Centre d'aide et File Exchange

Produits

Version

R2023a

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by