Assigning a single value to cell array with logical indexing.
이전 댓글 표시
Hi All,
I am wondering if the code I have below is optimal for what it does, or if there are better ways to do this.
VDIV{1} = [2 5 7 10 13 13.2 20 30 50 100 200 500 1000]*1E-3;
VDIV{2} = [VDIV{1} 5 10];
numVDIVs = numel(VDIV{2});
AmpLimitField = cell(numVDIVs,1);
[AmpLimitField{VDIV{2} < 102E-3}] = deal('X1');
[AmpLimitField{VDIV{2} >= 1.02}] = deal('X100');
% When VDIV{2} >= 102E-3 && VDIV{2} < 1.02}
[AmpLimitField{cellfun(@isempty,AmpLimitField)}] = deal('X10');
Outputs:
AmpLimitField =
'X1'
'X1'
'X1'
'X1'
'X1'
'X1'
'X1'
'X1'
'X1'
'X1'
'X10'
'X10'
'X10'
'X100'
'X100'
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!