How to delete duplicate values from an array or a vector

How to delete duplicate values from an array or a vector
Hi, how do I delete duplicate values from an array or a vector provided that unique function is not used and that the place of the value does not remain empty or zero. The result is like this
a=[1 2 3 6 1 3 1];
a=[1 2 3 6]
b=[1 1 3
3 4 5
4 9 1];
b=[1 3 4 5 9]

5 Comments

Since it is a homework problem, show us what you've done and where you are stuck.
Hello, it is not homework and I am trying to make an array without duplicates to create a box for encrypting the data
clear all;clc;
r=0.2;x(1,1)=0.8;
for i=2:64
x(i)=r+(1-x(i-1))^2;
end
A=reshape(x,8,[]);
u1=0.15;u2=0.13;Y(1)=0.2; X(1)=0.6;m1=2.76;m2=3.45;n=15;
for i=1:63
X(i+1)=m1*x(i)*(1-x(i))+u1*Y(i)^2;
Y(i+1)=m2*Y(i)*(1-Y(i))+u2*((X(i)^2)+X(i)*Y(i));
end
B=reshape(X,8,[]);
AB=([A,B])
r = 28; b = 8/3;
yy(1) = 20; z0(1) = 30; Q=10;
for i=2:64
X3d(i)=Q*(Y(i-1)-X(i-1));
yy(i)=r*X(i-1)-yy(i-1)-X(i-1)*z0(i-1);
z0(i)=X(i-1)*yy(i-1)+b*z0(i-1);
end
C=reshape(X3d,8,[]);
D=reshape(z0,8,[]);
CD=([C,D]);
all_matrix=([AB;CD]);
new_allmatrix =round(mod(all_matrix*10^5,256));
new_allmatrix =
128 151 252 249 49 224 191 178 0 39 95 255 36 123 157 237
192 60 40 63 172 217 235 242 128 56 46 121 250 175 96 198
192 145 73 180 21 213 187 176 144 37 217 220 154 126 179 44
114 69 136 100 187 223 237 243 121 132 231 242 118 100 44 156
43 11 190 126 255 204 183 175 211 135 164 64 38 55 52 159
2 16 212 130 200 228 239 244 8 183 44 39 63 22 28 161
86 225 80 83 238 197 180 173 66 77 256 125 22 166 146 196
220 174 15 154 209 232 241 245 83 162 166 108 48 116 194 115
96 7 22 171 155 111 225 237 192 37 210 36 0 0 0 0
216 65 140 217 91 156 150 41 128 157 194 160 0 0 0 0
197 71 113 3 232 161 106 253 165 75 250 64 0 0 0 0
188 35 135 128 198 169 228 78 5 252 165 128 0 0 0 0
224 8 93 230 254 17 248 14 172 69 30 0 0 0 0 0
193 184 99 152 2 234 140 132 159 130 41 0 0 0 0 0
124 23 91 201 29 213 202 215 169 38 138 0 0 0 0 0
70 71 49 112 72 153 195 59 179 87 80 0 0 0 0 0
If it isn't homework, then why isn't the unique() function allowed?
@Matt J Exactly, so valid Question
:)
This function is useless by working on the idea I am working on, which is the process of generating numbers through static equations to create a random 16 * 16 matrix. Thank you.

Sign in to comment.

 Accepted Answer

Jan
Jan on 10 Feb 2021
Edited: Jan on 10 Feb 2021
b=[1 1 3
3 4 5
4 9 1];
% The clean solution:
b = unique(b(:).')
% [1 3 4 5 9]
% Without unique:
bs = sort(b(:).');
result = bs([true, diff(bs) ~= 0])
% [1 3 4 5 9]
% For a stable output (order of elements does not change):
[bs, vec] = sort(b(:).');
uvec(vec) = [true, diff(bs) ~= 0];
result = b(uvec);
% [1 3 4 5 9]

More Answers (0)

Asked:

on 10 Feb 2021

Commented:

on 10 Feb 2021

Community Treasure Hunt

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

Start Hunting!