フィルターのクリア

Calculation of a sum with variable values from textbox prompt

4 ビュー (過去 30 日間)
sverre Kvist
sverre Kvist 2023 年 9 月 4 日
編集済み: Matt J 2023 年 9 月 4 日
Hi,
I'm looking to get an user input on amount of Resistors, then make an array with that number. Then make a prompt with an input for each resistor value, to be added to the array.
My concrete question is in regards to the prompting, how do i get multiple edit fields in the promt, and connect them to the array,
also accept suggestions for the summing too.
Formula i wish to calculate:
Code so far:
clc, clear, close all;
prompt = {'Enter number of resistors:'};
dlgtitle = 'Number of resistors';
dims = [1 35];
definput = {'1'};
Resistors = inputdlg(prompt,dlgtitle,dims,definput);
R_array = zeros(1,str2double(Resistors(1)))
  3 件のコメント
Dyuman Joshi
Dyuman Joshi 2023 年 9 月 4 日
"how do i get multiple edit fields in the promt"
Refer to the documentation page of inputdlg on how to get multiple inputs.
You will get the inputs in the form of a cell array, manipulate them according to your requirements.
sverre Kvist
sverre Kvist 2023 年 9 月 4 日
Thank you for the feedback.
I figured out a way. For reference if other people have the same, or similar question:
prompt = {'Resistors in paralell:'};
dlgtitle = 'Number of resistors';
dims = [1 35];
definput = {'1'};
Resistors = inputdlg(prompt,dlgtitle,dims,definput);
R_array = zeros(1,str2double(Resistors(1)));
for i=1:numel(R_array)
temparr{i} = "Resistor";
end
x = inputdlg(temparr);
sum = 0;
for i=1:numel(x)
sum = sum + (1/str2double(x{i}));
end
R_total = sum^-1

サインインしてコメントする。

採用された回答

Matt J
Matt J 2023 年 9 月 4 日
編集済み: Matt J 2023 年 9 月 4 日
Then make a prompt with an input for each resistor value
It shouldn't require multiple prompts,
nor a loop to do the summation:
>> x=inputdlg
x =
1×1 cell array
{'[1,2,3,4]'}
>> sum(str2num(x{1}))
ans =
10

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeArray Geometries and Analysis についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by