Comparing value in m x n matrices to find its index
조회 수: 1 (최근 30일)
이전 댓글 표시
Hi, I have one set of data that I need to compare it with different size of data. So, as it stated in this code below, the threshold will be 3, 3.5, 4, 4.5 ..... I have to compare each threshold with all available data in variable GtrecMRCG2 then get its index. after all data compared, I need to check it with remaining threshold in variable thresholdVAR.
I wrote this based on my understanding. but it doesn't work because the dimension is mismatched. Thank you so much and big appreciation to those who want to give me advises. :)
threshold = 3;
thresholdVAR=[threshold 0 0 0 0 0 0 0 0];
GtrecMRCG2= [ 5 8 9 6 2 5 2 4 6 3 8 9 11];
for ii=1:9
thresholdVAR(ii+1:end)= thresholdVAR(ii)+ 0.5;
end
for idxm=1:length(thresholdVAR)
for idxn = 1:length(GtrecMRCG2)
idxalarmMRCG (1:length(thresholdVAR),1:length(GtrecMRCG2))= find(GtrecMRCG2(idxm,idxn)>=thresholdVAR(idxm,idxn));
end
end
댓글 수: 4
CS Researcher
2016년 5월 1일
Not exactly sure what you are trying to achieve but you should see the line with the code:
find( thresholdVAR(idxm:sza(1),idxn:sza(2)) < GtrecMRCG2(1:sza(1),1:sza(2)));
Your thresholdVAR and GtrecMRCG2 are not 2D matrices. They both are 1D vectors.
Also, you don't need a loop to initialize the thresholdVAR. You can just do this:
thresholdVAR = 3:0.5:7;
채택된 답변
Ilham Hardy
2016년 5월 2일
Something like this?
thresholdVAR = 3:0.5:7;
GtrecMRCG2= [ 5 8 9 6 2 5 2 4 6 3 8 9 11];
% preallocate
DesMat = zeros(length(thresholdVAR),length(GtrecMRCG2));
for oneL = 1:length(thresholdVAR)
[r,c,v] = find(GtrecMRCG2>thresholdVAR(oneL));
DesMat(oneL,c) = GtrecMRCG2(c);
end
추가 답변 (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!