Include all possible combinations in loop?

2 views (last 30 days)
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

Accepted Answer

Matt J
Matt J on 21 Jul 2023
%% '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 Comments
VBBV
VBBV on 21 Jul 2023
Edited: VBBV on 21 Jul 2023

@Lauren , Use a [ ] concatenation operator for R2_all instead of () parenthesis for the matrix.

Sign in to comment.

More Answers (0)

Products


Release

R2022a

Community Treasure Hunt

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

Start Hunting!