Include all possible combinations in loop?

2 Ansichten (letzte 30 Tage)
Lauren-Xante Claassen
Lauren-Xante Claassen am 21 Jul. 2023
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

Akzeptierte Antwort

Matt J
Matt J am 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 Kommentare
VBBV
VBBV am 21 Jul. 2023
Bearbeitet: VBBV am 21 Jul. 2023

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

Lauren-Xante Claassen
Lauren-Xante Claassen am 21 Jul. 2023
Bearbeitet: Lauren-Xante Claassen am 21 Jul. 2023
Thank you both!!!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange

Produkte


Version

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by