How can I modify the chart font size/style using m script
1 次查看(过去 30 天)
显示 更早的评论
-> Using graphical interface I am able to modify the font size and style for each state and trasition at once using Chart->Format->FontSize
-> to modify the format using m script I tried using TransitionFont and StateFont of Chart property but result is not same as manually setting Format for chart using abovestep.
-> Could you please help me out how can we change the char Format properties using m script
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1447247/image.png)
1 个评论
dpb
2023-8-1
I don't recognize the UI to which that belongs...is that, I guess, Simulink?
Every handle graphics object has an object handle and a set of properties; to modify them programmatically you would need to have the handle of the subject object (either saved when created programmatically or by "handle-diving" to find the desired object as a child of the figure/axes). You then use that handle and the property name/value pair via set or directly through the "dot" notation referencing the property.
I have no idea what 'TransitionFont' nor 'StateFont' refer to, specifically, but I would expect you're looking for just 'FontName'
hAx=axes('visible','off'); % an ordinary MATLAB axes object but not shown
hF=gcf; hF.Visible='off'; % hide the figure, too
s=fieldnames(get(hAx)); % the struct of the handle object names
s(startsWith(s,'Font')) % those that directly set font properties
So, with ordinary plots/figures, there isn't such properties as the above, they're those shown.
But, of course, it's not clear what chart object you're looking at, but some similar sort of spelunking should let you know what you're looking for.
If nothing else, you can dump all the properties, then change via the UI and then see what was changed...assuming you can get programmatic access to the chart dynamically.
回答(1 个)
Shivang
2023-8-21
Hi Aruna,
I understand that you're trying to modify the font size of States and Transitions programmatically. You've tried to modify properties of the Chart such as 'StateFont', but this hasn't had the intended effect.
Please know that modifying the 'StateFont' property of the Chart will not modify the font sizes of existing states. This action only sets the default size for new states, as is mentioned in the following: https://in.mathworks.com/help/stateflow/api/stateflow.chart.html
In order to modify the properties of existing states, first use the ‘find’ function to find the handles to existing states in your Chart. In this regard, please find the sample code below for a Chart “ch”:
states = find(ch,"-isa","Stateflow.State")
The variable states would now contain a State array. You can further modify the font size of a given State using the 'FontSize' property.
For example, to set the font size of the first State to 20, you can use the following code:
states(1).FontSize = 20
If you look at the Stateflow chart now, you will find that the font size of the first State in the chart has been updated.
You can modify the properties of other Chart objects in a similar fashion.
I hope this helps!
2 个评论
Shivang
2023-8-21
编辑:Shivang
2023-8-21
Aruna,
I am able to run a command like
states(1).FontSize = 10.2
without running into errors. If you're encountering an error, please post the error message.
As I explained in my answer, modifying the font size in 'StateFont' will not affect any existing Chart objects. If you want to update the font size of all States in your chart, you can use the 'set' function. The code would be
set(states,"FontSize",20)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Stateflow Programmatic Interface 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!