Resize only height, not width of spectrogram

Whenever I try to resize the height of a spectrogram in app designer, it seems that the ratio of the image size stays the same. How can I resize only the height, but no the width of a spectrogram?

回答 (1 件)

dpb
dpb 2022 年 9 月 21 日
編集済み: dpb 2022 年 9 月 21 日

0 投票

You don't show how you're trying the resize operation but spectrogram(...) plots into the current axes and if you size the axes as desired first, it will plot into it without modifying the size.
Or, you can programmatically retrieve the axes .Position property and adjust height/width as desired and then place it back...
...
hAx=gca; % get the current axes handle
p=hAx.Position; % retrieve position vector (left,bottom,width,height)
p(4)=0.75*p(4); % reduce height 25%
hAx.Position=p; % set new position
...

5 件のコメント

LabRat
LabRat 2022 年 9 月 21 日
I am resizing the spectrogram through the GUI in "App Designer"
LabRat
LabRat 2022 年 9 月 21 日
When I try to use 'p(4)' I get
"invalid expression. Check for missing multiplication operator, missing or unbalanced delimiters, or
other syntax error. To construct matrices, use brackets instead of parentheses."
dpb
dpb 2022 年 9 月 21 日
There isn't a "spectrogram" as a component; it has to be drawn into an axes...and an axes has the four-vector 'Position' property that you can set at design time as wish. With an app, you'll then have to ensure the desired axes is current one (if there's more than one in your application) to ensure it is plotted where intended since spectrogram doesn't allow one to specify a specific axes handle.
dpb
dpb 2022 年 9 月 21 日
編集済み: dpb 2022 年 9 月 21 日
Your second comment wasn't visible when I responded above...ships passing in the night and all that...but--
Insufficient information to be able to know what went wrong -- need all the code in context associated with the attempt to change the size -- you didn't even copy the offending line that generated the error, what more the context in which it existed that defined p, etc., etc., ...
The code snippet shown definitely will work -- if there is an existing axes and it's the one desired, it will have the desired effect. IF, however, there isn't an active axes, then gca will create one and that well may NOT be the one associated with the app that you're interested in.
There's just too much not being passed along for us to know just what's going on here...as the other comment says, if the idea is to create and fix an axes position at design time and have it be fixed, then editing the 'Position' vector in the design mode for the particular axes will be the way to go.
We can't see your terminal from here; all we know is what is posted...
dpb
dpb 2022 年 9 月 21 日
hAx=gca;
box on
p=hAx.Position % show default figure position 4-vector
p = 1×4
0.1300 0.1100 0.7750 0.8150
figure % force a new figure
axes; % and an axes in it...
box on
hAx(2)=gca; % get its handle now...
p(4)=0.75*p(4); % make this one shorter vertically
hAx(2).Position=p; % set the new position, show values for grins
hAx(2).Position
ans = 1×4
0.1300 0.1100 0.7750 0.6113
You can observe the second outlined is 3/4 the height of the first...

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

カテゴリ

ヘルプ センター および File ExchangeTime-Frequency Analysis についてさらに検索

質問済み:

2022 年 9 月 21 日

コメント済み:

dpb
2022 年 9 月 21 日

Community Treasure Hunt

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

Start Hunting!

Translated by