Why does my cellfun fails?
이전 댓글 표시
Hello
I have the following cell where I would like to replace all 1 by 'true' and all 0 by 'failed'
a= [ 0] [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11]
[ 1] [0] [0] [0] [0] [0] [0] [0] [0] [0] [ 0] [ 0]
[ 2] [1] [1] [1] [0] [0] [1] [0] [0] [0] [ 0] [ 0]
[ 3] [1] [1] [1] [0] [0] [1] [0] [0] [0] [ 0] [ 0]
[ 4] [1] [1] [1] [0] [0] [1] [0] [0] [0] [ 0] [ 0]
[ 5] [1] [1] [1] [0] [0] [1] [0] [0] [0] [ 0] [ 0]
[ 6] [1] [1] [1] [0] [0] [1] [0] [0] [0] [ 0] [ 0]
[ 7] [1] [1] [1] [0] [0] [1] [0] [0] [0] [ 0] [ 0]
[ 8] [1] [1] [1] [0] [0] [1] [0] [0] [0] [ 0] [ 0]
[ 9] [1] [1] [1] [0] [0] [1] [0] [0] [0] [ 0] [ 0]
[10] [1] [1] [1] [0] [0] [1] [0] [0] [0] [ 0] [ 0]
[11] [1] [1] [1] [0] [0] [1] [0] [1] [0] [ 0] [ 0]
If I apply the command
a(cellfun(@(elem) elem == 0,a)) = {'false'}
I get s
a= [ false] [1] [2] [3] [4] [5] [6] [7] [8] [9] [1false] [11]
[ 1] [false] [false] [false] [false] [false] [false] [false] [false] [false] [ false] [ false]
....
The output expected, however if I try to apply the same command again as
a(cellfun(@(elem) elem == 1,a)) = {'true'}
it fails and matlab says
Error using cellfun
Non-scalar in Uniform output, at index 2, output 1.
Set 'UniformOutput' to false.
Which I don't understand, further if I set the value as indicated I get
a(cellfun(@(elem) elem == 1,a,'UniformOutput',false)) = {'true'}
Function 'subsindex' is not defined for values of class 'cell'.
How can I change the 1 to 'true'?
Thanks in advance
댓글 수: 1
Kevin Chng
2018년 10월 12일
편집: Kevin Chng
2018년 10월 12일
sorry, i'm curious how you assign your 'a' variable in MATLAB?
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Structures에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!