How to neatly take user input as function input
이전 댓글 표시
I have a function in which I would like the user to input an argument. Currently I have:
%take user input and set to var 'spike_threshold'
spike_threshold = inputdlg('Choose a firing threshold in Vm (default, 20)');
spike_threshold = str2num(spike_threshold{1,1});
if isempty(spike_threshold);
spike_threshold = 10;
end
%use 'spike_threshold' as an input argument to a function
[spike_counts, Cell_info.spikeinfo] = spike_extractor(Vm, time, current_injections_norm_vector, spike_threshold);
This works fine but takes up a lot of space, I have a few functions where I would like the user to input 2-3 arguments. Is there a way to have this process embdeded within the function? I tried this but it required the input variable to be defined in the script the function was called from. This would be better, but still a little messier than I'd like - is it possible to have this process entirely self-contained within the function? Cheers.
댓글 수: 2
Bob Thompson
2019년 2월 28일
is it possible to have this process entirely self-contained within the function?
I'm a bit confused. Are you asking if it is possible to insert an input command into a function directly? Yes, and it works the same way as in a script.
I tried this but it required the input variable to be defined in the script the function was called from
You tried what, exactly? It sounds like you tried to use the 'input' command within a function, which should work fine. If you did try putting the input command into your functions, what errors did you encounter, or what results did you get, and how were they different from what you were expecting?
Joe_Z
2019년 3월 2일
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Scripts에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!