invalid filename saving figure

I am trying to save this figure using the following code, however I keep getting the error "invalid filename".
Str2 consists of a combination of text and values, to create a unique name, corresponding to the figure at hand. However, something, somewhere goes wrong. I have tried to remove the .png and add it to the saveas command. I have tried to name my figure, like f=figure(), but I cannot discover my error. Any solutions?
figure(2)
hold on
plot(output_time,Principal_stress_fatigue_fy_mx/10^6)
ylabel('equivalent stress [MPa]')
xlabel('time [s]')
grid
str2="Figure2"+ VTRIM + bank_angle + roll_rate + AC_mission_type(j)+".png"
saveas(gcf,str2)

10 件のコメント

Abderrahim. B
Abderrahim. B 2022 年 8 月 24 日
編集済み: Abderrahim. B 2022 年 8 月 25 日
Hi!
Can you tell us what is the data type of VTRIM , bank_angle , roll_rate
Rose
Rose 2022 年 8 月 24 日
VTRIM=80 %kts
bank_angle=45 %deg
roll_rate=10 %deg/s
Walter Roberson
Walter Roberson 2022 年 8 月 24 日
and AC_mission_type(j) ?
By the way you should either be using fixed width formats with 0 fill, or else you should be using delimiters between the parts. for example bank rate 4, roll 28 would generate the same name as bank rate 42 roll 8
Rose
Rose 2022 年 8 月 25 日
The AC_mission_type is included in a for loop. So the plots will be created for the combination of bank angle, roll rate and VTRIM for each of these mission types.
AC_mission_type ={ 'design','extended', 'maximum alternate'}
It is no problem for mee that 428 could mean 2 things, as I only assume a couple of predefined scenario's. But thank you for the advice!
Bruno Luong
Bruno Luong 2022 年 8 月 25 日
I hope j is scalar, otherwise str2 is an array.
Could it be that the absolute path + filename is too long for the OS filesystem?
Walter Roberson
Walter Roberson 2022 年 8 月 25 日
Could you show us an example of the str2 when there is a failure ?
Rose
Rose 2022 年 8 月 25 日
編集済み: Rose 2022 年 8 月 25 日
to answer both your questions:
j=1:length(AC_mission_type)
and:
Str2=
"Figure2804510design.png"
Walter Roberson
Walter Roberson 2022 年 8 月 25 日
As an experiment, try
saveas(gcf, char(str2))
Rose
Rose 2022 年 8 月 25 日
it works! Thank you!
Walter Roberson
Walter Roberson 2022 年 8 月 25 日
Odd. You filled out R2021a as your release, but string() was supported for that parameter in R2021a. R2017a was the last release that did not support string() for that parameter.

サインインしてコメントする。

回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeInteractive Control and Callbacks についてさらに検索

製品

リリース

R2021a

質問済み:

2022 年 8 月 24 日

コメント済み:

2022 年 8 月 25 日

Community Treasure Hunt

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

Start Hunting!

Translated by