Hello, I am trying to export my plot to pdf and want the file_name to match with a variable string. I have tried different solutions, but unfortunetaly none of them works for. I saw it is not same as the save() command. Could you possibly help please ?
Here you can see the crucial part of my code, I tried different approaches here.
plot(x1,y1u,x1,y1d,x2,y2u,x2, y2d) %profil
hold on
plot(x1,y_p1(f,x,x1),x2,y_p2(f,x,x2)) %střední křivka
hold off
title('NACA',str)
xlim([0 1])
ylim([-0.5 0.5])
grid on
%Basicly the main problem, str is defined more upwards in my code
file_name = ['Profil_',str];
exportgraphics(gcf,'C:\Users\danie\OneDrive\Plocha\Matlab\Vzor\US_ISA\'+ file_name +'.pdf','ContentType','vector')
exportgraphics(gcf,file_name)

 Respuesta aceptada

Voss
Voss el 2 de Abr. de 2022
str = 'whatever';
file_name = ['Profil_',str];
% use string concatenation (notice the double-quotes)
"C:\Users\danie\OneDrive\Plocha\Matlab\Vzor\US_ISA\"+ file_name +".pdf"
ans = "C:\Users\danie\OneDrive\Plocha\Matlab\Vzor\US_ISA\Profil_whatever.pdf"
% or character vector concatentation (single quotes with [ ] around the whole thing)
['C:\Users\danie\OneDrive\Plocha\Matlab\Vzor\US_ISA\' file_name '.pdf']
ans = 'C:\Users\danie\OneDrive\Plocha\Matlab\Vzor\US_ISA\Profil_whatever.pdf'
% mixing them doesn't work:
'C:\Users\danie\OneDrive\Plocha\Matlab\Vzor\US_ISA\'+ file_name +'.pdf'
Arrays have incompatible sizes for this operation.

2 comentarios

Daniel Miarka
Daniel Miarka el 2 de Abr. de 2022
Thank you very much, second solution worked for me. At a first one, exportgraphics() do not allow me double quotes. But second solution is working proprely, thank you very much.
Voss
Voss el 2 de Abr. de 2022
You're welcome!
If your MATLAB version is a few years old, you wouldn't be able to create a string using double-quotes, so that may be why the first way didn't work. (I don't know the exact version of MATLAB when this was first supported, but it definitely doesn't work in R2016b, for instance.)
If you don't mind, please click "Accept this Answer", so that others who run into the same problem can see there is a solution. Thanks!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Productos

Versión

R2021a

Preguntada:

el 2 de Abr. de 2022

Comentada:

el 2 de Abr. de 2022

Community Treasure Hunt

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

Start Hunting!

Translated by