a=[2 3 7 1 4 2 1 2 8 2 5 9 2 10 12 1 2 6];
b=unique(a);
[b m n]=unique(a);
counts=accumarray(n(:),1)
for k=1:numel(counts)
fprintf('the value %d appears %d times in a\n',...
b(k),counts(k));
end
q = 0; r = 0; s = 0; t = 0; u = 0; v = 0;
for i=1:counts
if(counts(i)==1)
q = 0;
disp('q=0');
end
if(counts(i)==2)
r = 0;
disp('r=0');
end
if(counts(i)==3)
s = 3;
disp('s=3');
end
if(counts(i)==4)
t = 6;
disp('t=6');
end
if(counts(i)==5)
u = 10;
disp('u=10');
end
if(counts(i)==6)
v = 15;
disp('v=15');
end
end
sum = q + r + s + t + u + v;
fprintf('Sum = %d\n',sum);
Don't start new threads with the same content. Threads merged [alexan_e]
a=[2 3 7 1 4 2 1 16 8 2 5 9 15 10 12 1 26 6];
b=unique(a);
[b m n]=unique(a);
counts=accumarray(n(:),1)
for k=1:numel(counts)
fprintf('the value %d appears %d times in a\n',...
b(k),counts(k));
end
q = 0; r = 0; s = 0; t = 0; u = 0; v = 0;
for i=1:counts
if(counts(i)==1)
q = 0;
disp('q=0');
end
if(counts(i)==2)
r = 0;
disp('r=0');
end
if(counts(i)==3)
s = s + 3;
disp('s=3');
end
if(counts(i)==4)
t = t + 6;
disp('t=6');
end
if(counts(i)==5)
u = u + 10;
disp('u=10');
end
if(counts(i)==6)
v = v + 15;
disp('v=15');
end
end
sum = q + r + s + t + u + v;
fprintf('Sum = %d\n',sum);
x = input('Enter Matrix: ');
OutPut:
Enter Matrix: (here it will wait for input like) [2 3 1 4 5 8 9 10](enter)
you want to replace repeated value with any value other then that or any value other then the whole matrix.?Then how can we replace the repeated value with another one?
clc
clear
m = [1 1 1; 5 5 5; 12 12 12];
n = m;
s = size(m);
k = 0; vac = 0;
for i = 1 : s(1)
for j = 1 : s(2)-1
for z = j+1 : s(2)
if(n(i,j) == n(i,z))
vac = vac+1;
if(vac >= 2)
if(n(i,z) < 12)
n(i,z) = n(i,z) + 1;
else n(i,z) = n(i,z) - 1;
end
end
end
end
vac = 0;
end
end
m
n
A=[1 2 3 4 5 6 7 8 9];
Mat(1,1:3) = A(1:3);
Mat(2,1:3) = A(4:6);
Mat(3,1:3) = A(7:9);
Mat
Back = [Mat(1,1:3) Mat(2,1:3) Mat(3,1:3)];
Back
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?