change variable name

1 view (last 30 days)
Baba
Baba on 2 Nov 2011
I would like to be able to Change 'X7' to anything else in psdest and title. So for instance instead of manually chaning it in both places, I'd like to just have one place that I'd have to change this in.
Here is my code:
subplot(3,2,1)
Hs=spectrum.periodogram;
psdest = psd(Hs,X7,'Fs',Fs);
semilogx(psdest.Frequencies,10*log10(psdest.Data));
grid on;
xlabel('Frequency (Hz)')
ylabel('dB/Hz')
title('X7')

Accepted Answer

Fangjun Jiang
Fangjun Jiang on 2 Nov 2011
In one place, X7 is a variable. In the second place, 'X7' is a string. I am not sure what you try to do, but I don't see a real value for doing this. It is possible though,
Str='X7';
psdest = psd(Hs,eval(Str),'Fs',Fs);
title(Str);

More Answers (1)

Walter Roberson
Walter Roberson on 2 Nov 2011
function psdplot(InputVar)
subplot(3,2,1)
Hs=spectrum.periodogram;
psdest = psd(Hs,InputVar,'Fs',Fs);
semilogx(psdest.Frequencies,10*log10(psdest.Data));
grid on;
xlabel('Frequency (Hz)')
ylabel('dB/Hz')
title(inputname(1))
Then call
psdplot(X7)

Categories

Find more on Dialog Boxes in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!