how to save variable data that we changed ?

7 ビュー (過去 30 日間)
NUR BATRISYIA HANNANI ZAIN AZMI
NUR BATRISYIA HANNANI ZAIN AZMI 2021 年 3 月 9 日
回答済み: TED MOSBY 2024 年 8 月 25 日
this is my code:
nSamp = 3251;
Fs = 1024e3;
SNR = 40;
rng default
t = (0:nSamp-1)'/Fs;
x = sin(2*pi*t*100.123e3);
x = x + randn(size(x))*std(x)/db2mag(SNR);
[Pxx,f] = periodogram(x,kaiser(nSamp,38),[],Fs);
meanfreq(Pxx,f);
i change the variable in this code to my dataset . then after run, the variable go to its original data . how to solve this problem?
  9 件のコメント
Walter Roberson
Walter Roberson 2021 年 3 月 11 日
What is the source of your signal? Is it stored in a .mat file at the moment? Does it need to be read from a .wav ?
NUR BATRISYIA HANNANI ZAIN AZMI
NUR BATRISYIA HANNANI ZAIN AZMI 2021 年 3 月 11 日
yes in mat file .

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

回答 (1 件)

TED MOSBY
TED MOSBY 2024 年 8 月 25 日
I understand that you want to change the value of a variable in the workspace. The problem you are facing is because you are changing the values in the workspace but that is not the right way as the variables in the workspace are generated after the script is executed.
So, changing the values in the workspace won’t help as when you run the script again it will generate the values according to the code and not take the values of the workspace.
So, to change any value of the variable you must modify the script. You can make your code as a function and then call it as shown below:
function plotPeriodogram(x)
nSamp = numel(x);
Fs = 1024e3;
SNR = 40;
rng default
x = x + randn(size(x)) * std(x) / db2mag(SNR);
[Pxx, f] = periodogram(x, kaiser(nSamp, 38), [], Fs);
meanFreq = meanfreq(Pxx, f);
disp(['Mean Frequency: ', num2str(meanFreq)]);
end
plotPeriodogram(myNewData);
Hope this helps!

カテゴリ

Help Center および File ExchangeProgramming についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by