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 个评论
更多回答(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!