change variable name
1 次查看(过去 30 天)
显示 更早的评论
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')
0 个评论
采纳的回答
Fangjun Jiang
2011-11-2
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);
0 个评论
更多回答(1 个)
Walter Roberson
2011-11-2
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)
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Dialog Boxes 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!