Include all possible combinations in loop?

조회 수: 5 (최근 30일)
Lauren-Xante Claassen
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

채택된 답변

Matt J
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
VBBV
VBBV 2023년 7월 21일
편집: VBBV 2023년 7월 21일

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

Lauren-Xante Claassen
Lauren-Xante Claassen 2023년 7월 21일
편집: Lauren-Xante Claassen 2023년 7월 21일
Thank you both!!!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by