How can I modify the chart font size/style using m script

2 visualizaciones (últimos 30 días)
Aruna
Aruna el 1 de Ag. de 2023
Editada: Shivang el 21 de Ag. de 2023
-> 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
  1 comentario
dpb
dpb el 1 de Ag. de 2023
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
ans = 7×1 cell array
{'FontName' } {'FontAngle' } {'FontWeight' } {'FontSmoothing'} {'FontUnits' } {'FontSize' } {'FontSizeMode' }
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.

Iniciar sesión para comentar.

Respuestas (1)

Shivang
Shivang el 21 de Ag. de 2023
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 comentarios
Aruna
Aruna el 21 de Ag. de 2023
Thanks for the discription Shivang, As you said I am doing same process but when I am getting individual state size for few states its showing as below
states(1).FontSize = 10.2(float value instead of decimal) for these states through script its showing error as the value can't set but, I can able to set it manually.
If you know could you please let me know how to proceed and it will be gratefull if you provide me the command to set the front setting using 'StateFont' property of the Chart also.
Shivang
Shivang el 21 de Ag. de 2023
Editada: Shivang el 21 de Ag. de 2023
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)

Iniciar sesión para comentar.

Productos


Versión

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by