index in safe-title

2 vues (au cours des 30 derniers jours)
Lukas Netzer
Lukas Netzer le 6 Mai 2021
Commenté : Lukas Netzer le 10 Mai 2021
I would like to define my file with the title, so that includes the according index. I tried:
saveas(gcf,'title_t{n}','jpeg')
saveas(gcf,'title', t{n},'jpeg')
Either wont work - is there a way?
Thanks in advance!

Réponse acceptée

Steven Lord
Steven Lord le 6 Mai 2021
Try:
str = "title_" + t{n}
saveas(gcf,str,'jpeg')
This will attempt to convert t{n} into a string and concatenate the string "title_" and that newly created string. I've defined it as a separate variable so you can see what it looks like. If this doesn't do what you want, show us the value of str that is displayed when you run this code and describe how it differs from how you want it to look.
  1 commentaire
Lukas Netzer
Lukas Netzer le 10 Mai 2021
thank you!!

Connectez-vous pour commenter.

Plus de réponses (1)

KSSV
KSSV le 6 Mai 2021
saveas(gcf,[title_t{n},'jpeg'])
  4 commentaires
Lukas Netzer
Lukas Netzer le 6 Mai 2021
Hey Walter!
Either you used one bracket too much or too little. I tried:
saveas(gcf,['title_' t{n}],'jpeg')
which gives me:
Error using saveas (line 96)
Invalid filename.
Walter Roberson
Walter Roberson le 6 Mai 2021
What datatype is t{n} ? If it is numeric then
filename = sprintf('title_%g.jpg', t{n});
saveas(gcf, filename, 'jpeg')

Connectez-vous pour commenter.

Catégories

En savoir plus sur Characters and Strings dans Help Center et File Exchange

Produits


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by