I'm creating an array [array 1] that fulfills the formula (A - B/C), where A and B are matrices with different elements and C is a matrix with a constant value. I then want to make another array [array 2] which is dependent on the values obtained from the formula in array 1.
So in array 2, I want it to check for values greater than 0.5 and set those to 0, and values less than or equal to 0 to be set to 1.
However, as A and B both begin at a value of 0; the first element in array 1 will be 0, making the first element of array 2 1.
How could I ignore this value?
I've currently made array 2 by doing:
A_2 = (A_1<= 0.5 & A_1>=0)

댓글 수: 1

dpb
dpb 2017년 12월 23일
I couldn't tell what you want the end result to be, sorry. Give us a really small example input/output as illustration.

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

 채택된 답변

dpb
dpb 2017년 12월 23일
편집: dpb 2017년 12월 24일

0 개 추천

Having read the question multiple times now, the crystal ball is suggesting you simply wanted to treat the first element uniquely. The simplest way to do this is to just add the additional rule after done creating A_2--
A_2 = (A_1<= 0.5 & A_1>=0); A_2(1) = 0;
The ways to write the addressing to only operate on the elements of A_1 excluding (1,1) end up either being quite messy or returning the result as a vector of N-1 elements that has to be reshaped so it's easier to just brute-force it since it's just the one case/element.
ADDENDUM To generalize if there were ever a case that wanted other than the one constant would be to write
A_2 = (A_1<= 0.5 & A_1>=0); A_2(1) = A_1(1);

댓글 수: 3

Image Analyst
Image Analyst 2017년 12월 24일
He wanted " to check for values greater than 0.5 and set those to 0, and values less than or equal to 0 to be set to 1." and that code changes the values in between 0 and 0.5 whereas my code leaves them alone and does exactly what was asked. Since he accepted your answer, all I can guess is that mathman must have meant "less than or equal to 0.5" even though he did not write that. I'll have to ask for a copy of that Crystal Ball Toolbox.
mathman
mathman 2017년 12월 24일
Sorry that was an error. I did write it in the code I provided though, which is what dpb used.
dpb
dpb 2017년 12월 25일
Well, actually I just divined what OP meant the question to be regarding the one value and presumed that his code otherwise was providing the result desired so really paid no attention to that portion...addressing only how to treat the one location uniquely explicitly. :)

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

추가 답변 (1개)

Image Analyst
Image Analyst 2017년 12월 23일

0 개 추천

Try this:
a2 = A1; % Initialize
zerosMask = a2 > 0.5;
a2(zerosMask) = 0;
onesMask = a2 < 0;
a2(onesMask) = 1;

카테고리

도움말 센터File Exchange에서 Crystals에 대해 자세히 알아보기

태그

질문:

2017년 12월 23일

댓글:

dpb
2017년 12월 25일

Community Treasure Hunt

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

Start Hunting!

Translated by