2 outputs from a function (pwelch) into a cell array

I am using the function pwelch to calculate the PSD of my signal. Currently, I am doing
[pxx,f] = pwelch(data,50000,[],[],Fs);
for a single window value. However, I need to test several window values so I created
pwelchvalues= [10000 50000 100000 250000 500000 750000];
But now I don't know how to modify the left side of the equation. I cannot use just
[pxx,f] =
because the pxx's and f's of each value will be of different length. I have tried for loops, cellfun and several combinations like
[pxx{:},f{:}] = pwelch(data, pwelchvalues,[],[],Fs);
but I keep getting error like: "Cell contents assignment to a non-cell array object." or "Error: Unbalanced or unexpected parenthesis or bracket."
What is the correct syntax?

 採用された回答

Walter Roberson
Walter Roberson 2017 年 7 月 29 日

0 投票

[pxx, f] = arrayfun(@(W) pwelch(data, W, [], [], 2048), pwelchvalues, 'uniform', 0);

4 件のコメント

ErikaZ
ErikaZ 2017 年 7 月 29 日
編集済み: ErikaZ 2017 年 7 月 29 日
I don't understand when and how to use arrayfun and cellfun. For example, now I need to plot the equivalent of
semilogx(f,20*log10(pxx));
In other words, I want to plot all 4 columns of each pxx (total of 24 PSDs) with their respective f in a single figure.
Walter Roberson
Walter Roberson 2017 年 7 月 29 日
X = f;
Y = cellfun(@(p) 20*log10(p),pxx,'uniform', 0);
XY = [X(:); Y(:)] ;
semilogx(XY{:})
You might want to consider just using a loop.
ErikaZ
ErikaZ 2017 年 7 月 31 日
I ended up using a for loop because the top code didn't quite work even with some changes. Thanks!
Walter Roberson
Walter Roberson 2017 年 7 月 31 日
X = f;
Y = cellfun(@(p) 20*log10(p),pxx,'uniform', 0);
XY = [X(:).'; Y(:).'] ;
semilogx(XY{:})

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeSignal Processing Toolbox についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by