Why does this not work? How do I ask the user questions involving changing variables?

3 件のコメント

Ajay Kumar
Ajay Kumar 2019 年 11 月 4 日
Please try to insert code instead of uploading a picture. No one likes to write the full code from a picture.
Ruger28
Ruger28 2019 年 11 月 4 日
What are you having trouble with, exactly?
Emma Sellers
Emma Sellers 2019 年 11 月 4 日
For some reason my copy and paste no longer works in my editor. I've checked all my shortcuts and theyre one there - but it still does not work.

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

 採用された回答

JESUS DAVID ARIZA ROYETH
JESUS DAVID ARIZA ROYETH 2019 年 11 月 4 日

1 投票

solution:
answer=inputdlg({'nodes'});
nodes=str2double(answer(1,1));
nodematrix=Inf(nodes);
A=0;
B=1;
while A<nodes
B=B+1;
A=A+1;
answer=input(['Enter resistance between ',num2str(A),' and ',num2str(B)])
end

4 件のコメント

Emma Sellers
Emma Sellers 2019 年 11 月 4 日
Is there a way I can do this with inputdlg? I tried and it just split my question up really strangley.
Emma Sellers
Emma Sellers 2019 年 11 月 4 日
answer = inputdlg({'Enter resistance between ',num2str(A),' and ', num2str(B)''})
JESUS DAVID ARIZA ROYETH
JESUS DAVID ARIZA ROYETH 2019 年 11 月 4 日
something like this?
answer=inputdlg({'nodes'});
nodes=str2double(answer(1,1));
nodematrix=Inf(nodes);
A=0;
B=1;
answer=[];
while A<nodes
B=B+1;
A=A+1;
answer(end+1)=str2double(inputdlg(['Enter resistance between ',num2str(A),' and ',num2str(B)]));
end
disp(answer)
Emma Sellers
Emma Sellers 2019 年 11 月 4 日
Yes! Thank you!

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

その他の回答 (2 件)

Steven Lord
Steven Lord 2019 年 11 月 4 日

0 投票

For this you could use num2str as JESUS DAVID ARIZA ROYETH posted, but I'd prefer either creating a string array to pass to the input function (if you're using a release of MATLAB that contains the string class) or using sprintf. Here's how you can use string (this requires you to use release R2017a or later to create a string using double quotes.)
A = randi([1 10]); % A scalar integer value between 1 and 10 inclusive
x = input("What positive number when squared gives " + A^2 + "? ");
if x == A
disp("Correct!")
else
disp("Incorrect, the correct answer is " + A + ".")
end
For sprintf:
k = 2;
s = sprintf('The value of %d*pi is approximately %f.', k, k*pi)
Priyanka Saxena
Priyanka Saxena 2023 年 7 月 18 日

0 投票

I want a matlab implementation for fast slic

カテゴリ

ヘルプ センター および File Exchange で Environment and Settings についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by