Include all possible combinations in loop?
조회 수: 5 (최근 30일)
이전 댓글 표시
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!