필터 지우기
필터 지우기

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

조회 수: 1 (최근 30일)
Aruna
Aruna 2023년 8월 1일
편집: Shivang 2023년 8월 21일
-> 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
dpb
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
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.

댓글을 달려면 로그인하십시오.

답변 (1개)

Shivang
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
Aruna
Aruna 2023년 8월 21일
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 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 CenterFile Exchange에서 Stateflow Programmatic Interface에 대해 자세히 알아보기

제품


릴리스

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by