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!