Equivalent of deal for a table
이전 댓글 표시
I often use deal to change the values of several cells in a cell array of strings:
a = 1:5;
b = {'one', 'two', 'three', 'four', 'five'};
[b{a>3}] = deal('big');
However, I just discovered that attempting the same operation on a table variable throws an error:
a = 1:5;
b = {'one', 'two', 'three', 'four', 'five'};
t = table(a,b);
[t.b{t.a>3}] = deal('big');
yields:
Expected one output from a curly brace or dot indexing expression, but there were 2
results.
Is there an equivalent syntax to quickly reassign values in a table?
댓글 수: 3
I fear that this will bring us directly back to the somehow long list of things that only built-ins can support, for a reason of parsing or of overloading of SUBSASGN/REF/etc, or ..(?) And table objects are not built-ins ( -> open table ).
If we
open deal
and place a break point on the first line of code, the "cell array"-based example leads to nargout=2 and the table-based example leads to nargout=1..
Kelly Kearney
2015년 7월 28일
Cedric
2015년 7월 29일
Hmm, not as bad as a rainbow color map ;-) but still.. well, hopefully this will become a built-in in a near future! (not 2015b though, because I have the same issue on the pre-release)
답변 (1개)
Bernard
2021년 2월 7일
It would be nice to have this functionality. In the meantime, this works, although not as elegant.
t.b(t.a>3) = repmat({'big'}, size(t.b(t.a>3)))
카테고리
도움말 센터 및 File Exchange에서 Structures에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!