Resize only height, not width of spectrogram

3 visualizzazioni (ultimi 30 giorni)
LabRat
LabRat il 21 Set 2022
Commentato: dpb il 21 Set 2022
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?

Risposte (1)

dpb
dpb il 21 Set 2022
Modificato: dpb il 21 Set 2022
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 Commenti
dpb
dpb il 21 Set 2022
Modificato: dpb il 21 Set 2022
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 il 21 Set 2022
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...

Accedi per commentare.

Categorie

Scopri di più su Time-Frequency Analysis in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by