Clear Filters
Clear Filters

Storing User Input in a Matrix

1 view (last 30 days)
Emma Sellers
Emma Sellers on 30 Sep 2019
Answered: Gregory McFadden on 30 Sep 2019
I am attempting to write code that takes user input in with the dialog boxes. But i need the user input to then be stored in a matrix as it is gathered.. Is there a way to do this? I have tried by places the dialog boxes in a while loop..
function[Source, resistors] = simplecircuit(voltage, current)
for cnt = 1:2
Source(cnt) = inputdlg({'Voltage Value','Node','Node'},...
'Source Placement',[1 10; 1 5; 1 5]);
end
for i = 1:2
resistors = inputdlg({'Resistor Value','Node','Node'},...
'Source Placement',[1 50; 1 12; 1 7]);
end
end

Answers (1)

Gregory McFadden
Gregory McFadden on 30 Sep 2019
Have you tried just making a GUI for this? It is particularly easy to just have a table and use the cell edit callback to perform an action whenever a cell is edited. If the table length is highly variable, either in the cell edit callback or with a different function, extra rows can be added only when necessary.
Either in Guide or appdesigner, it is quite easy to handle these types of input tasks, then just have a button to command execution of the rest of your code once the table is populated.

Tags

Community Treasure Hunt

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

Start Hunting!