cellfun can not combines the outputs in arrays, even the outputs have the same size?

조회 수: 30 (최근 30일)
I have a cell called acell like this:
acell{1} = [ 0.200404217804178, 0.923507089706316, 0.0655250892091169 ]
acell{2} = [ 0.620741132682194, 0.608315135231154, 0.83289817740182 ]
acell{3} = [ 0.024658375296586, 0.166032525166251, 0.706597370177546 ]
I want to do this command:
cellfun(@(x) x == 0, acell )
but get the error:
??? Error using ==> cellfun Non-scalar in Uniform output, at index 1, output 1. Set 'UniformOutput' to false.
It is strange that even the outputs have the same size, cellfun can not combines the outputs in arrays. That is in contradiction to the help document on cellfun. Am I doing something wrong here or I misunderstand the help document?
Thanks!

채택된 답변

Vishal Rane
Vishal Rane 2013년 6월 13일
Yang,
As per documentation on cellfun "UniformOutput 'true' indicates that for all inputs, each output from the function is a cell array or a scalar value that is always of the same type."
In your case each output is of the form [ x x x ], which is neither a cell array nor a scalar. Hence the need to set UniformOutput to false.
Refer these links isscalar and UniformOutput

추가 답변 (2개)

Azzi Abdelmalek
Azzi Abdelmalek 2013년 6월 13일
cellfun(@(x) x == 0, acell ,'un',0)

Yang
Yang 2013년 6월 14일
Thanks to Vishal and Azzi. It seems that to convert the same size output to matrix, we need to specify 'UniformOutput' false, then apply cell2mat to combine the outputs.
  댓글 수: 2
Ana Martínez
Ana Martínez 2016년 4월 18일
Hello! I have the same error, can you help me please??
How can I to convert PSS/E files into a MatPower case? I know that psse2mpc function converts a PSS/E RAW data file into a MATPOWER case struct, but when I do it, I get an error.
For instance, I want to prove a case with 9 Buses called "case9psse.raw", and I want to save the results in "MPC_prueba.m". So I have this:
MPC = psse2mpc('case9psse.raw','MPC_prueba.m')
But it show me this:
MPC = psse2mpc('case9psse.raw','MPC_prueba.m') Reading file 'case9psse.raw' ........................................... done. Splitting into individual lines ...................... 51 lines read ... done. Analyzing sections ..................................... 18 sections ... done. Attempting to determine PSS/E revision from content. Parsing case identification data ......... unknown rev, using rev 23 ... done. Parsing 9 lines of bus data .......................................??? Error using ==> cellfun Non-scalar in Uniform output, at index 1, output 1. Set 'UniformOutput' to false.
Error in ==> psse_parse_section at 211 data.num(:, c) = cellfun(xc_fcn, dd);
Error in ==> psse_parse at 157 [data.bus, warns] = psse_parse_section(warns, records, sections, s, verbose, ...
Error in ==> psse2mpc at 90 [data, warnings] = psse_parse(records, sections, verbose, rev);
It's the same advice that you had, but I don't undersntad how to solve it.
Satyaki Banik
Satyaki Banik 2020년 10월 13일
Hello Ana Martinez, I have encountered the same problem - "Error using ==> cellfun Non-scalar in Uniform output, at index 1, output 1. Set 'UniformOutput' to false." What is the solution to that?
Thanks in advance.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Structures에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by