Include all possible combinations in loop?
5 ビュー (過去 30 日間)
古いコメントを表示
Lauren-Xante Claassen
2023 年 7 月 21 日
編集済み: Lauren-Xante Claassen
2023 年 7 月 21 日
I want my code to compare a user input to eight values, find the ones greater than the user input and extract the corresponding columns from a matrix 'ConcreteData'. I then want it to return these columns in a new matrix called 'Sub_ConcreteData'. Presently, I am having to type a line of code for every possible combination which is very long and can accidentally omit a combination. Below Code shows what I would like it to do, whereby the code automatically searches through every possible combination from my R2 values and presents the new matrix.
CODE
%% 'ConcreteData' (matrix 1030x8)
R2_all = (value1,value2,value3,value4,value5,value6,value7,value8) %%pre-defined values
exit = false;
msg = 'Please enter an R^2 value:';
if ~exit
data = str2double(inputdlg(msg));
exit = (0 <= data & 1 >= data) %%user input
if ~exit
msg = 'Input must be between the values 0-1. Please re-enter: ';
end
if data > R2_all %% check all 8 values against user input
disp([]) %%return new matrix called 'Sub_ConcreteData', with any combination/number of columns from orignal matrix 'ConcreteData'
end
end
0 件のコメント
採用された回答
Matt J
2023 年 7 月 21 日
%% 'ConcreteData' (matrix 1030x8)
R2_all = (value1,value2,value3,value4,value5,value6,value7,value8) %%pre-defined values
exit = false;
msg = 'Please enter an R^2 value:';
while ~exit
data = str2double(inputdlg(msg));
exit = (0 <= data & 1 >= data) %%user input
if ~exit
msg = 'Input must be between the values 0-1. Please re-enter: ';
end
end
Sub_ConcreteData=ConcreteData(:, data > R2_all)
5 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Matrix Indexing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!