필터 지우기
필터 지우기

save only one value

조회 수: 1 (최근 30일)
Tomas
Tomas 2014년 3월 13일
편집: Salaheddin Hosseinzadeh 2014년 3월 18일
Hello,
I have for example matrix
MON = [2.8 3.6 17.2;
5.4 8.3 15.8;
2.5 3.2 17.6;
9.9 10.7 13.6;
5.5 8.9 15.5;
9.7 11 13.9;
2.3 3.9 17.9;
5.7 8.1 15.1;
9.4 10.5 13;
9.9 13.2 13.7];
I calculate distance between points from MATRIX.
or i=1:m % pre pocet objektov (pre kazdy riadok MON)
B = MON(i,:); % vloz i-ty riadok z MON do premennej B
for j=1:r % pre kazdy riadok TAZ
ED(j)= distance(TAZ(j,:),B,fff); %euklidovska vzdialenost
[minD, minI(idx)] = min([ED]); %minimalna hodnota a index
end
Then I want to save the smallest value to the cell.
[e,f]=size(ED);
for h=1:f
if (ED(h) == ED(minI(idx)))
Z{h}{z}=B;
z=z+1;
end
end
idx=idx+1;
end
If I have the same value is stored me both to cell. How i stored a just a single valu to cell.
For example ED=[4 4 6] I want only values from position ED(1) save to cell.
Thanks.
  댓글 수: 1
Image Analyst
Image Analyst 2014년 3월 15일
Why a cell instead of a regular numerical array which is much much easier to work with?

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

답변 (1개)

Salaheddin Hosseinzadeh
Salaheddin Hosseinzadeh 2014년 3월 13일
Sorry, but even your English is a bit confusing, just like mine! lol Is the problem of having two 4 bothers you?
If so then I guess you can use 'unique' to get rid of the repeated 4
ED= unique(ED,'stable') % this should give you ED=[4,6]
Sorry if I didn't get what's your problem, please explain more what do you want to happen.
Good Luck!
  댓글 수: 6
Tomas
Tomas 2014년 3월 15일
편집: Tomas 2014년 3월 15일
Yes, I'm sure,
??? Error using ==> unique at 34 Unrecognized option.
Error in ==> KMNS at 262 ED= unique(ED,'stable')
ED is for example ED=[inf NaN NaN] i want to have ED=[inf, NaN]
Salaheddin Hosseinzadeh
Salaheddin Hosseinzadeh 2014년 3월 18일
편집: Salaheddin Hosseinzadeh 2014년 3월 18일
First of all so sorry for getting back to you with a huge delay, you're problem is probably solved by now! so sorry
I read through the MATLAB help for 'unique()' and unfortunately it's clearly documented that 'unique treats NaN values as distinct'
So for your example we can't use unique anyway!
If the problem is only with NaN then it's easy
i=1;
NanCount=0;
while(i<= length(ED))
if(isnan(ED(i)))
if(NanCount>0)
ED(i)=[];
i=i-1;
end
NanCount=NanCount+1; % to see how many nan is omitted
end %end of if
i=i+1;
end %end of while
Number of omitted NaNs should equal NanCount-1
Sorry I don't have MATLAB now to try it. Give it a shot and let me know about the result.

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

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by