Filter löschen
Filter löschen

change variable name

1 Ansicht (letzte 30 Tage)
Baba
Baba am 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')

Akzeptierte Antwort

Fangjun Jiang
Fangjun Jiang am 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);

Weitere Antworten (1)

Walter Roberson
Walter Roberson am 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)

Kategorien

Mehr zu Environment and Settings finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by