Question is Unknown :)

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?

댓글 수: 2

Oleg Komarov
Oleg Komarov 2011년 6월 3일
Depends on what is event...
nsbd
nsbd 2011년 6월 3일
anything....Sample;
if answer == D{1}
disp(A{1})
elseif answer == D{2}
disp(A{2})
.....
...
elseif answer == D{n}
disp(A{n})
end

댓글을 달려면 로그인하십시오.

 채택된 답변

Sean de Wolski
Sean de Wolski 2011년 6월 3일

1 개 추천

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

nsbd
nsbd 2011년 6월 3일
Thks but I can't :(
Sean de Wolski
Sean de Wolski 2011년 6월 3일
What's the point of this? You already know answer, why not just display it?
nsbd
nsbd 2011년 6월 3일
D is {1}.... I will use , set(handles.variable,'string',A{3});

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by