How to neatly take user input as function input
Show older comments
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 Comments
Bob Thompson
on 28 Feb 2019
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
on 2 Mar 2019
Accepted Answer
More Answers (0)
Categories
Find more on Scripts in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!