Error using arrayfun : Non scalar in Uniform output

Hello,
I have a cell array (Z) of size (480*1) where in each row I have the individual double arrays that I want(e.g. 1*70 double). Now I want to apply a custom function to each row (each elements of the cell), for this I use arrayfun:
C = arrayfun(@ (x) (((a/length(Z))*(1/(2*pi))).*((abs(fftshift(fft(Z,1024))).^2))),1:480);
and I get this error:
Error using arrayfun Non-scalar in Uniform output, at index 1, output 1. Set 'UniformOutput' to false.
(Worth mentioning that I zeropad my fft, so the output data are all the same size(1*1024))

回答 (1 件)

Azzi Abdelmalek
Azzi Abdelmalek 2013 年 11 月 5 日
編集済み: Azzi Abdelmalek 2013 年 11 月 5 日

2 投票

Add 'uniformoutput',false or 'un',0
C = arrayfun(@ (x) (((a/length(Z))*(1/(2*pi))).*((abs(fftshift(fft(Z,1024))).^2))),1:480,'un',0);

4 件のコメント

Mona Mahboob Kanafi
Mona Mahboob Kanafi 2013 年 11 月 5 日
Thanks for your answer, but it shouldn't be the problem of output size since all outputs do to use of zeropadding must be of size 1*1024. With your correction the error will be:
Undefined function 'fft' for input arguments of type 'cell'.
Error in @(x)(((a/length(Z))*(1/(2*pi))).*((abs(fftshift(fft(Z,1024))).^2)))
Azzi Abdelmalek
Azzi Abdelmalek 2013 年 11 月 5 日
編集済み: Azzi Abdelmalek 2013 年 11 月 5 日
Change fft(Z,1024) by fft(x,1024)
C = arrayfun(@ (x) (((a/length(Z))*(1/(2*pi))).*((abs(fftshift(fft(x,1024))).^2))),1:480,'un',0);
Mona Mahboob Kanafi
Mona Mahboob Kanafi 2013 年 11 月 5 日
x in your expression is 1:480, while fft is going to be applied on each element of Z(as explained in my question) i.e. Z{1} which has 1*70 elements , then Z{2} having 1*58 elements,...
Azzi Abdelmalek
Azzi Abdelmalek 2013 年 11 月 5 日
Ok, then use cellfun
C = cellfun(@ (x) (((a/length(Z))*(1/(2*pi))).*((abs(fftshift(fft(x,1024))).^2))),Z,'uniformoutput',false);

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

カテゴリ

ヘルプ センター および File ExchangeLoops and Conditional Statements についてさらに検索

質問済み:

2013 年 11 月 5 日

コメント済み:

2013 年 11 月 5 日

Community Treasure Hunt

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

Start Hunting!

Translated by