save only one value

1 view (last 30 days)
Tomas
Tomas on 13 Mar 2014
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 Comment
Image Analyst
Image Analyst on 15 Mar 2014
Why a cell instead of a regular numerical array which is much much easier to work with?

Sign in to comment.

Answers (1)

Salaheddin Hosseinzadeh
Salaheddin Hosseinzadeh on 13 Mar 2014
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 Comments
Tomas
Tomas on 15 Mar 2014
Edited: Tomas on 15 Mar 2014
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 on 18 Mar 2014
Edited: Salaheddin Hosseinzadeh on 18 Mar 2014
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.

Sign in to comment.

Tags

Community Treasure Hunt

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

Start Hunting!