Storing User Input in a Matrix

3 次查看(过去 30 天)
Emma Sellers
Emma Sellers 2019-9-30
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

回答(1 个)

Gregory McFadden
Gregory McFadden 2019-9-30
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.

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by