필터 지우기
필터 지우기

Help with logical indexing

조회 수: 1 (최근 30일)
Barry
Barry 2020년 12월 18일
답변: Rishabh Mishra 2020년 12월 21일
Hi All,
i have a question about logical indexing.
I have an array of three columns called pressure. Firstly, i check for values < 1000 (low = pressure < 1000) and then i would like to give those values new RGB values [0.1, 0.5, 0.9] so i can create a RGB pressure map.
i tried pressure(low) = [0.1, 0.5, 0.9] but this obviously didnt work. pressure(low) = 0.9 is working but is not the prefered outcome.
Any idead how this might work? Or do i have apply every column seperately like this: pressure(low, 1) = 0.1, pressure(low, 2) = 0.5 ... and so on?
Regards,
Barry
  댓글 수: 1
KALYAN ACHARJYA
KALYAN ACHARJYA 2020년 12월 18일
"values < 1000 (low = pressure < 1000)"
Please carify?
  • For for individual coloums or all columns have to satisfy
  • How does you get thease R,G,B values 0.1, 0.5, 0.9
If you want help, then you need to make it easy to be helped.
:)

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

답변 (1개)

Rishabh Mishra
Rishabh Mishra 2020년 12월 21일
Hi,
You can use cell arrays (instead of double arrays) along with loop operations to work out the issue. Use the code below for the purpose,
% Pressure Matrix
pressure = [1101 450 987;1213 145 1997;148 1533 1420];
low = pressure < 1000;
RGB = {0.1 0.5 0.9};
% Convert Matrix to 2D Cell Array
pressure = num2cell(pressure);
% Replace Pressure values < 1000 by RGB cell
for k = 1:size(low,1)
for j = 1:size(low,2)
if low(k,j)
pressure{k,j} = RGB;
end
end
end
Hope this helps.

카테고리

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

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by