How to save user input as variable I can compare?

2 ビュー (過去 30 日間)
Lauren-Xante Claassen
Lauren-Xante Claassen 2023 年 7 月 19 日
コメント済み: Star Strider 2023 年 7 月 20 日
I am trying to generate by Linear regression to get value a, then I want to get user input value b. So I can then take value a and b and plot them on a curve. But my user input is not storing values?
% Linear regression model: y ~ 1 + x1, calculate R^2 values for each ingredient
Mdl1=LinearModel.fit(SortedData_Cement(:,1),SortedData_Cement(:,9));
R^2_Cement = Mdl1.Rsquared.Ordinary;
Mdl1=LinearModel.fit(SortedData_Blastfurn(:,2),SortedData_Blastfurn(:,9));
R^2_Blastfurn = Mdl1.Rsquared.Ordinary;
% Prompt user to input a value for R^2 for all ingredients, accepting or rejecting value within a range. Display message to user.
exit=false;
msg='Please enter an R^2 value for Cement:';
while ~exit
data = str2double( inputdlg(msg) );
exit = (0<= data && 1>=data);
if ~exit
msg = 'Input must be between the values 0-1. Please re-enter: ';
end
end
exit=false;
msg='Please enter an R^2 value for Blast Furnace:';
while ~exit
data = str2double( inputdlg(msg) );
exit = (0<= data && 1>=data);
if ~exit
msg = 'Input must be between the values 0-1. Please re-enter: ';
end
end

採用された回答

Star Strider
Star Strider 2023 年 7 月 19 日
The ‘data’ values are geing read correctly, however the second ‘data’ assignment is overwriting the first one.
Perhaps:
data(1) = str2double( inputdlg(msg) );
and:
data(2) = str2double( inputdlg(msg) );
with appropriate references to each of them in the test comparisons would work. (I subscripted them here, although anything that makes them different would work.)
.
  2 件のコメント
Lauren-Xante Claassen
Lauren-Xante Claassen 2023 年 7 月 20 日
Of course, thank you for your time!
Star Strider
Star Strider 2023 年 7 月 20 日
As always, my pleasure!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDownloads についてさらに検索

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by