Question is Unknown :)
조회 수: 1 (최근 30일)
이전 댓글 표시
Hi guys.
"
D=importdata('data 1.xls');
% (D= '11'
'12'
'13'
'14'
'15'
'16'
....
...
..
. )
if answer == D{1}
%event
elseif answer == D{2}
%event
elseif answer == D{3}
%event
elseif answer == D{4}
%event
...
...
elseif anser == D{n}
%event
end
hard to write by hand is too long
how do i write this shorter? or did can be done?
채택된 답변
Sean de Wolski
2011년 6월 3일
Define your event to take in the index, e.g:
function event(val,idx);
%do stuff with val,idx
end
Then call it with:
idx = find(cellfun(@(c)c==answer,D),1,'first');
event(D{idx},idx);
EDIT per comment:
idx = find(cellfun(@(c)c==answer,D),1,'first');
disp(D{idx})
댓글 수: 3
Sean de Wolski
2011년 6월 3일
What's the point of this? You already know answer, why not just display it?
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 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!