Error with table subtraction
이전 댓글 표시
At the line d1, error appears that '-' is undefined operator. If bsxfun is used, error on numeric arrays is shown. Conversion of table type (before and after d1) leads to different errors. Please, suggest suitable modification with data format table.
a=[0.5;0.6;0.9;1.0;1.6]
b=[2.0;1.5;1.3;2.8;3.2]
c=[-0.1;0.4;0.5;1.1;1.4]
T=table(a,b,c)
for i=2:size(T,1)
if T{i,'a'}>T{i-1,'a'}
d=min(T{i,:})
else
d=0
end
d1=sum(d-T,2)
end
댓글 수: 1
To suggest suitable modification we would first need to know what it is you intended doing. As it is, your loop is pointless since it overwrites d at each step, so only the last iteration of the loop will have an effect on d.
subtraction is not defined for tables, so once again it's not clear what you intended to do with your last line, nor why you're using a table in the first place.
Also note that your table has only one row. Did you mean
T = table(a', b', c', 'VariableNames', {'a', 'b', 'c'})
instead?
채택된 답변
추가 답변 (1개)
Guillaume
2018년 1월 4일
A complete guess, since you haven't explained what you're trying to do:
a=[0.5 0.6 0.9 1.0 1.6];
b=[2.0 1.5 1.3 2.8 3.2];
c=[-0.1 0.4 0.5 1.1 1.4];
m = [a;b;c]';
d = min(m, [], 2);
d([true; diff(m(:, 1)) <= 0]) = 0;
%these last two lines could also be written as the slightly more obscure one-liner:
% d = min(m, [], 2) .* [0; diff(m(:, 1)) > 0];
d1 = sum(d-m, 2)
Using a table for this does not make sense.
카테고리
도움말 센터 및 File Exchange에서 Logical에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!